O'Reilly Forums: Problems With Linqpad And Ef4.2 Codefirst - O'Reilly Forums
Page 1 of 1
Problems With Linqpad And Ef4.2 Codefirst
Posted 12 October 2011 - 12:00 AM
i cant manage to create a connection using EF4.2 CodeFirst. (LinqPAD 4.36.2)
I used Entity Framework (POCO) connection and entered my DLL, which was correctly recognized. I selected the Context datatype and after that the app.config, no problem so far.
But after clicking OK the connection is marked with a red cross and the tooltip states the following error messge (roughly translated into english, i use a german framework version):
The Object of type P32EBDataContext (this is my context class) cannot be convertes into type System.Data.Entity.Infrastructure.IObjectContextAdapter
Am i doing something wrong? Or isnt it possible with this version?
Posted 12 October 2011 - 07:51 PM
LINQPad doesn't as yet support EF 4.2. However you can work around the problem by adding a binding redirect.
Modify the LINQPad.exe.config as follows:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0"/> </startup> <runtime> <legacyUnhandledExceptionPolicy enabled="1" /> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" /> <bindingRedirect oldVersion="18.104.22.168" newVersion="22.214.171.124" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
Also, make sure you uninstall EF 4.1 if you haven't already done so.
This post has been edited by JoeAlbahari: 12 October 2011 - 07:53 PM
Posted 16 November 2011 - 07:29 AM
I have installed the latest beta (v4.36.5), uninstalled EF4.1 (actually update 1), added EF4.2 to additional references. The connection tests okay and there are no issues executing queries against the context.
But in the schema explorer window on the left it does not list the context's schema and has the error message: "MyContext (Error: could not load file or assembly 'EntityFramework, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.)"
Any idea on what could be wrong?
Posted 16 November 2011 - 11:45 PM
You'll either need to GAC EF 4.2 or ensure that its assembly is in the same folder as your typed DataContext. Otherwise LINQPad won't be able to find it.
You shouldn't need to add an explicit reference to the assembly in your queries (in fact, it won't help because at that point it's too late - LINQPad must be able to locate the EF assembly in order to infer the schema and populate the treeview - PRIOR to any queries running).
This post has been edited by JoeAlbahari: 16 November 2011 - 11:48 PM
Posted 01 December 2011 - 11:23 PM
I followed @JoeAlbahari's instructions and installed EF 4.2 in the GAC. Merely having EntityFramework.dll in the same folder as the dll with the context reference didn't work.
BUT - a new problem has arisen: some days after everything was working, any queries against the context throw an exception:
The type or namespace name 'Infrastructure' does not exist in the namespace 'System.Data.Entity' There was also an assembly reference error - press F4 to fix: Metadata file 'EntityFramework.dll' could not be found
I thought it may have been caused by the installation of EntityFramework.Migrations (the only change) but I removed it - and still the same exception. I built another EF 4.2 POCO context with Migrations and it works fine.
Any suggestions on how to fix this?
Posted 20 December 2011 - 08:40 AM
I had those problems too, however it works for me doing the following:
a.) I create a "dynamic" DBContext which creates the DBSets dynamically based on my assembly. This has to be in the linqpad folder
b.) My dbcontext is build against a newer version of EF4 that 188.8.131.52 so I got first the error that LINQPAd cannot find 184.108.40.206. I donwloaded that dll and did put it into the linqpad folder all works.
HOWEVER that whole code first makes to me no sense in LINQPAD as it is the same as connecting directly to the database. I will start a separate thread to ask if I am doing something wrong here.
Share this topic:
Page 1 of 1
1 User(s) are reading this topic