O'Reilly Forums: Problems With Linqpad And Ef4.2 Codefirst - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problems With Linqpad And Ef4.2 Codefirst Rate Topic: -----

#1 User is offline   Olaf K. 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 11-October 11

Posted 12 October 2011 - 12:00 AM

Hi,

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?

Thanks
Olaf
0

#2 User is offline   JoeAlbahari 

  • Super Veteran Member
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 529
  • Joined: 15-February 08
  • Gender:Male
  • Location:Perth, Australia

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="4.1.0.0" newVersion="4.2.0.0" />
      </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

0

#3 User is offline   JoeAlbahari 

  • Super Veteran Member
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 529
  • Joined: 15-February 08
  • Gender:Male
  • Location:Perth, Australia

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!

Joe
0

#4 User is offline   Tomfy 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 16-November 11

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=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.)"

Any idea on what could be wrong?

Tim
0

#5 User is offline   JoeAlbahari 

  • Super Veteran Member
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 529
  • Joined: 15-February 08
  • Gender:Male
  • Location:Perth, Australia

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

0

#6 User is offline   docgregt 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 30-November 11

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.

Thanks,
Greg
0

#7 User is offline   Tomfy 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 16-November 11

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?
0

#8 User is offline   joer00 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 11
  • Joined: 07-December 10

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 4.2.0.0 so I got first the error that LINQPAd cannot find 4.2.0.0. 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.

Joe Robe
0

#9 User is offline   JoeAlbahari 

  • Super Veteran Member
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 529
  • Joined: 15-February 08
  • Gender:Male
  • Location:Perth, Australia

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.

Joe
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users