43

I just downloaded entity framework 6 and created a brand new project to test it. We currently use EF 5.

After adding all my tables and stored procedures, I tried to build the project but I get errors:

Value of type 'System.Data.Objects.ObjectParameter' cannot be converted to 'System.Data.Entity.Core.Objects.ObjectParameter'.

Value of type 'System.Data.Entity.Core.Objects.ObjectResult(Of DataLibrary.MyStoredProc_Result)' cannot be converted to 'System.Data.Objects.ObjectResult(Of DataLibrary.MyStoredProc_Result)'.

I cannot figure out why this will not work out-of-the-box

EF 5 had so such issues.

I am using VS 2012. .Net 4.5 Vb.net (also tried with a C# project... same issue)

Any ideas?

EDIT:

The answer was to install EF6 Tools for VS 2012. I did not know I had to do this since I thought that was installed when I added the Entity Framework package.

3
  • 2
    IMO, it SHOULD be installed with the EF6 package.
    – AJ.
    Oct 30, 2013 at 18:03
  • Yes You are right. You have to install EF 6.0 tool and uninstall older version.
    – user3163625
    Jan 5, 2014 at 22:24
  • same thing here, EF5 no such problem. First occuring in EF6.
    – Veverke
    Nov 12, 2015 at 17:15

3 Answers 3

99

You can overcome this scenario by replacing:

using System.Data.Objects;

With:

using System.Data.Entity.Core.Objects;

You may need to update the using statements in your T4 templates, like your Context.tt file, so that auto-generated files continue to work when re-generating.

Before

enter image description here

After

enter image description here

4
  • 1
    Wow, that actually worked for me as well. Saved me a big headache! This error originated in VS2013 for me, new project. 2012 never touched it.
    – NOCARRIER
    Dec 17, 2013 at 7:08
  • 2
    Worked for me, I did NOT have to install the EF tools for VS2012 only made the change above Mar 31, 2014 at 10:26
  • 4
    I assume this is done in MyContext.Context.cs file. This file is auto generated, so manual changes will be overwritten if the code is regenerated..
    – IAmGroot
    Apr 11, 2014 at 9:37
  • 13
    @Doomsknight Update the using statements in your T4 templates, like your Context.tt file, so regenerations continue to work. Apr 11, 2014 at 13:51
38

I guess you are using EF tools from VS2012 which are still bound to original EF distribution (part of .NET framework). EF6 uses out-of-band distribution and it doesn't work with previous tooling - that is the reason why those types has little bit different namespaces and cannot be converted from one to another.

Solution should be downloading and installing EF6 tools for VS2012 or using VS2013 where tools should be included.

2
  • 1
    I needed to change the references like in the answer below as well.
    – ekenman
    Aug 22, 2014 at 7:58
  • I have VS 2012 Update 4 and I have installed the EF 6 tools from the above link, but it still refrences the wrong namespace... Ok, now I can update the namespace in my .tt file, but the generated method expects an Array of ObjectResult not an object of ObjectResult.
    – Legends
    Apr 10, 2015 at 19:43
1

I used what "Pauly Glott", which worked for me. For a little more detailed info, see my post in Microsoft forums and the answer.

http://social.msdn.microsoft.com/Forums/en-US/9ac881f5-18f5-4aa4-bd99-94b1fa4c37c2/why-i-am-getting-errors-like-value-of-type-systemdataobjectsobjectparameter-cannot-be?forum=adodotnetentityframework

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.