LLBLgen Entity framework generation

Posts   
1  /  2
 
    
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 12-Nov-2012 22:56:42   

Hello,

I switched from LLBLgen framework to Entity framework generation.

Now i created a small project to as a test project.

But i have a problem that i don't understand.

Steps overview

1) Create table country and add some ... 2) Run LLBLgen tool and use database with country table 3) I Selected Entity framework v4.0 and select SD.Entityframework.v4 (DbContext API) 4) use nuget to add entity framework to persistence project 5) Add missing refference to other project 6) Create new console project with references

I created this peace code to test

MyDataContext dc = new MyDataContext ();

            var lijst = from x in dc.Countries select x;

            foreach (Country land in lijst)
            {
                Console.WriteLine(land.Description);
            }

This is the CORRECT SQL that is generated:

lijst = {SELECT 
[Extent1].[Active] AS [Active], 
[Extent1].[Countrycode2] AS [Countrycode2], 
[Extent1].[Countrycode3] AS [Countrycode3], 
[Extent1].[Description] AS [Description], 
[Extent1].[Id] AS [Id]
FROM [dbo].[Country] AS [Extent1]}

but in the foreach i have an error, "An error occurred while executing the command definition. See the inner exception for details."

inner exception -->

Invalid object name 'dbo.Country

The stange part is when i run the select statement i get result in management studio.

Can anyone help me out on this problem i have.

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Nov-2012 06:31:58   

Please post the full exception information (exception message and stack trace). It could be that you didn't add the appropriate connection string to the console's app.config file.

David Elizondo | LLBLGen Support Team
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 13-Nov-2012 18:46:35   

The connectionstring is not the problem.

That is present in my app.config. :-)

This is the stacktrace:

  at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
   at ConsoleDemo.Program.Main(String[] args) in c:\Users\Kris\Desktop\Generation\ConsoleDemo\Program.cs:line 19
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

This is message:

An error occurred while executing the command definition. See the inner exception for details.

This is inner exception:

Invalid object name 'dbo.Country'.
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 13-Nov-2012 19:07:25   

one thing i forgot to say:

In the project settings i go to Entity Framework v4

In general > Provider manifest token value - i add the value 2008

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Nov-2012 19:21:34   

How do you the connectionString is not the problem? Did you copy the connection string as is from the generated code to the console project config file?

Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 13-Nov-2012 20:45:50   

yes in the persistence project there is an app.config file with the connectionstring inside.

That one i create a copy and paste it inside my app.config console demo.

I comment the connection string and did the test, this is the (logical) error i get:

No connection string named 'ConnectionString.SQL Server (SqlClient)' could be found in the application config file.

Now this is my config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <!-- please adjust the connection string embedded in the element below to target the proper catalog / server using the proper user / password combination -->
    <add name="ConnectionString.SQL Server (SqlClient)" connectionString="metadata=res://*/KrisTEST.csdl|res://*/KrisTEST.ssdl|res://*/KrisTEST.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xxxxxxxxxxxx;initial catalog=master;User ID=xxxxxxxxxx;Password=xxxxxxxxxx;persist security info=False;packet size=4096&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>

    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Nov-2012 06:18:38   

The connection string is there, but Are you connecting to the correct server/db? Did you run the executed SQL on an DB script?

The query in your first post looks right, so we assume is something else on the DB you are connection to. Is that the sabe server/db you used to create the LLBLGen project?

David Elizondo | LLBLGen Support Team
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 14-Nov-2012 07:48:13   

Hello,

This database is only located in my Dev evironment. :-)

There is only one existing, so i can not be wrong about that.

Like i said:

  • SQL statement that it's generate works perfectly in my sql management studio.
  • The connection string in my console project is checked ...
  • The connectionstring has the only database there is
  • The user that is in the connectionstring is the same as the user used for llblgen generated files.
  • If I remove the connectionstring i get error that the conncetionstring is not found.

I do not understand what's wrong

I am using LLBLgen Pro v3.5 Final (september 17th, 2012)

My next steps: - Check if i have the latest version of llblgen - create a small test application connecting to northwind. and post it to this forum.

tbc

Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 14-Nov-2012 08:30:16   

My demo is size 2 MB

Now i send it in 2 parts

(Part I)

Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 14-Nov-2012 08:30:51   

Part II

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 14-Nov-2012 10:04:47   

Don't post binaries and databases we already have. Northwind is a sqlserver example database. Please post only sourcecode, namely the console application you made, and the llblgenproj file.

It really looks like the app connects with the wrong DB/catalog.

also, do you log into SSMS with the same account as specified in your connection string?

Frans Bouma | Lead developer LLBLGen Pro
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 14-Nov-2012 11:55:23   

Ok, sorry for the files ... you can remove it.

Know my questions:

1) Does the code work @ your place?

2) You are saying that it connects with the wrong DB/catalog.

The only option is that is connectring to the database or not at all. Because there is only one dev environment.

I have this problem with 2 solutions i created different database (same machine).

When i create a entity framework with Visual studio there is no problem working with Entity framework.

I looks like the app is connecting wrong

... there is only the connectionstring as solution for that.

but it's a copy paste from the config generated in the persistence project.

I would like to use LLBLgen tool for creating partial classes in the future ...

But if i can't get it to work then i have to look for some other solution that generates partial classes.

Please look at my code, i think it's something small i forgot

Thank you for your time.

Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 14-Nov-2012 14:06:24   

Ok i used SQL Server Profiler to check if the select statement send to the database.

And **Yes **i get the statement.

This is the output:

SQL:BatchStarting SELECT [Extent1].[Address] AS [Address], [Extent1].[City] AS [City], [Extent1].[CompanyName] AS [CompanyName], [Extent1].[ContactName] AS [ContactName], [Extent1].[ContactTitle] AS [ContactTitle], [Extent1].[Country] AS [Country], [Extent1].[CustomerID] AS [CustomerID], [Extent1].[Fax] AS [Fax], [Extent1].[Phone] AS [Phone], [Extent1].[PostalCode] AS [PostalCode], [Extent1].[Region] AS [Region] FROM [dbo].[Customers] AS [Extent1] EntityFrameworkMUE sa 3500 61 2012-11-14 14:00:29.847 SQL:BatchCompleted SELECT [Extent1].[Address] AS [Address], [Extent1].[City] AS [City], [Extent1].[CompanyName] AS [CompanyName], [Extent1].[ContactName] AS [ContactName], [Extent1].[ContactTitle] AS [ContactTitle], [Extent1].[Country] AS [Country], [Extent1].[CustomerID] AS [CustomerID], [Extent1].[Fax] AS [Fax], [Extent1].[Phone] AS [Phone], [Extent1].[PostalCode] AS [PostalCode], [Extent1].[Region] AS [Region] FROM [dbo].[Customers] AS [Extent1] EntityFrameworkMUE sa 0 4 0 1 3500 61 2012-11-14 14:00:29.847 2012-11-14 14:00:29.847

sourcecode:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Northwind.DAL;

namespace Console.Demo
{
    class Program
    {
        static void Main(string[] args)
        {

            System.Console.WriteLine("START");

            using (NorthwindDataContext dc = new NorthwindDataContext())
            {
                var lijst = from x in dc.Customers select x;

                foreach (var customer in lijst)
                {
                    System.Console.WriteLine(customer.CompanyName);
                }
            }
            
            System.Console.WriteLine("END");
            System.Console.ReadKey();
        }
    }
}

see attach for llblgen project.

tbc

Attachments
Filename File size Added on Approval
Northwind.DEMO.llblgenproj 44,471 14-Nov-2012 14:06.57 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 14-Nov-2012 14:30:42   

And the code above, does generate the exception dbo.Customer not found? We'll look into it. The EF code works fine here, so I'm a bit confused why it gives an exception that a table isn't found...

Frans Bouma | Lead developer LLBLGen Pro
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 14-Nov-2012 14:45:49   

Please look at my screenshot.

More details:

LLBLgen select EntityFramework V4.0

References to Entityframework 4.4.0.0 from nuget -> packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll

Model project -> .net 4.0 Persistence project -> .net 4.0 Console --> .net 4.0

I am using "C:\Program Files (x86)\Solutions Design\LLBLGen Pro v3.5" on w7 64bit machine.

Do i have to select "LLBLGen Pro v3.5 (on .NET 4.0 or 4.5, Any CPU)" ?

Attachments
Filename File size Added on Approval
llblgen.png 143,801 14-Nov-2012 14:45.55 Approved
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Nov-2012 18:14:53   

Could you please try using ADO.NET code with the same connection string, and see if you have access to dbo.Customers?

Also the code you found at the SQLProfiler, did you manage to run it in SQL Server M. Studio using the same username and pswd as in the config file?

Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 14-Nov-2012 21:08:22   

Could you please try using ADO.NET code with the same connection string, and see if you have access to dbo.Customers?

I can do that for you but i know the answer for that. (That is working)

Also the code you found at the SQLProfiler, did you manage to run it in SQL Server M. Studio using the same username and pswd as in the config file?

Yes

I run my console application with SQLprofiler running.

The sql statement retrieved with the sql profiler is from my consoleproject. My consoleproject is using entity framework. Does this mean that there is a connection problem ? (I think not)

In Sql management studio i can run the same statement with the same user. (It's sa user btw)

Now the data is retrieved when i have SQL:BatchCompleted ... or am i getting this wrong ?

Let's try something else.

Create some new llblgen project and connect to northwind database. add a new console project that is retrieving the customers.

If it works send all those files to me including llblgen project.

I will change the connectionstring and it should work here.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Nov-2012 05:18:40   

Everything works just perferct over here. I attached the code in case it would help you. However I don't think the problem is in the code (neither generated or custom code).

I think the problem could be actually on the EntityFramework build. See these posts: http://forums.asp.net/t/1830404.aspx/1 http://entityframework.codeplex.com/workitem/595

The second one doesn't seem to be the same case, but you never know.

Could you please try unisntalling EntityFramework and then install it again? (just EF, not prebuilds, betas or builds with debug symbols).

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 15-Nov-2012 10:29:15   

Could you try EF v5 from nuget? It works on .net 4 as well.

Frans Bouma | Lead developer LLBLGen Pro
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 15-Nov-2012 10:35:10   

Ok i will try that

but i found this identical problem http://weblogs.asp.net/jalpeshpvadgama/archive/2011/07/05/invalid-object-name-with-entity-framework-efcodefirstctp5.aspx

Changing default Plural Table name to that of the Entity Name which is Singular.

Now i notice that windows default is unselecting that option.

See sceenshot

Is there something in llblgen i have to change ?

Later on i do some tests

tbc

Attachments
Filename File size Added on Approval
sshot-4.png 41,064 15-Nov-2012 10:35.25 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 15-Nov-2012 12:25:04   

No that's something else, that's forward mapping with code first. Code first doesn't have an EDMX file, so it has to re-verse engineer the model in memory from the elements at hand. This is different, as the situation here is that the edmx file IS present.

I think I found it though simple_smile In the connection string you posted, you'll see this: initial catalog=master;. This is likely the culprit. Change 'master' into the catalog you're connecting with.

Problem is that we connect to 'master' to do multiple catalogs in the project, and the name is then used to initially connect to the DB (as sqlserver uses 2-phase connections: connect to the DB service and then to the catalog).

I think you left that set to 'master' instead of changing it. This means that the queries are run on the master db, which of course doesn't have your tables.

Frans Bouma | Lead developer LLBLGen Pro
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 15-Nov-2012 12:50:09   

Thanks for the feedback.

problem solved.

But when you choose your database in llblgen it generate the config file with the wrong initial catalog.

Is this normal ?

other solution is 1 user 1 initial catalog.

thanks

Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 15-Nov-2012 15:57:48   

i created 1 new user and it has only 1 Database

This is generate the config with master also.

So you have to change it each time after generation.

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 15-Nov-2012 16:24:28   

What is the default database for that user set to?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 15-Nov-2012 16:46:41   

Kris wrote:

i created 1 new user and it has only 1 Database

This is generate the config with master also.

So you have to change it each time after generation.

No, the connection string is specified in your application's config file, and llblgen pro never overwrites that string. It also doesn't overwrite app.config files.

I agree though, if you have 1 catalog, it should default to that. We'll fix that in the next version.

Frans Bouma | Lead developer LLBLGen Pro
1  /  2