Jump to content
Problems With Linqpad And Ef4.2 Codefirst
8 replies to this topic
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="188.8.131.52" newVersion="184.108.40.206" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
Also, make sure you uninstall EF 4.1 if you haven't already done so.
Edited by JoeAlbahari, 12 October 2011 - 07:53 PM.
Posted 14 November 2011 - 06:58 PM
Update: Support for EF 4.2 (in the form of a binding redirect) has been added to the latest beta.
Note that you must UNINSTALL EF 4.1 (so that it's no longer in the GAC) in order for this to work!
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=220.127.116.11, 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).
Edited by JoeAlbahari, 16 November 2011 - 11:48 PM.
Posted 30 November 2011 - 07:19 AM
I am having the same problem. I am using LinqPad 4.37.2. Please assist with getting this to work with 4.1 as we are using that version in production.
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 18.104.22.168 so I got first the error that LINQPAd cannot find 22.214.171.124. 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.
Posted 20 December 2011 - 08:26 PM
The latest LINQPad beta doesn't statically reference EntityFramework.dll, so most (or all) of these problems should go away.
Let me know if it still isn't working for you.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users