11

I am trying to update an EDMX Stored Procedure and I am getting this error:

Cannot implicitly convert type System.Data.Entity.Core.Objects.ObjectResult<X> to System.Data.Objects.ObjectResult<X>

I am using Visual Studio 2012.

5 Answers 5

28

I had the error and none of these solutions worked (I was already using System.Data.Entity.Core.Objects, it was also in the context.tt, etc).

I eventually realised the problem lay between the keyboard and the chair. The stored proc finished with a select, but I was trying:

MyStoredProc_Result r = dbcontext.MyStoredPoc();

Instead of

MyStoredProc_Result r = dbcontext.MyStoredPoc().FirstOrDefault();
2
  • 1
    you are saving my time as I am not follow above instruction
    – Ajay2707
    Mar 11, 2016 at 10:27
  • 1
    a 'more perfect' answer.
    – Cos Callis
    May 31, 2016 at 19:06
12

Open the context.tt file in XML mode and change

using System.Data.Objects;

to

using System.Data.Entity.Core.Objects;
3
  • This worked for me. I'm not sure why Entity Framework doesn't handle this for me when I update my store procedure result structure. Nov 14, 2014 at 20:25
  • @Sachin : perfect answer
    – Gaurav123
    Jun 11, 2015 at 7:11
  • See answer from @SteveCav for 'best solution'...doesn't call on you to edit generated files.
    – Cos Callis
    May 31, 2016 at 19:07
0

Either use VS 2013 or download the new Entity Framework 6 Tools for Visual Studio 2012.

0
0

You only have to change "using System.Data.Objects" to "using System.Data.Entity.Core.Objects"

1
  • 3
    Welcome to Stack Overflow. It's usually a good idea to give a little explanation in answer to a question, as well as the correct response.
    – O. Jones
    Sep 2, 2014 at 14:29
0

You need to upgrade to the new Entity Framework 6 runtime.

Right-click on your project and select Manage NuGet Packages... Under the Online tab select EntityFramework and click Install Note: If a previous version of the EntityFramework NuGet package was installed this will upgrade it to EF6. Alternatively, you can run the following command from Package Manager Console:

PM> Install-Package EntityFramework

Reference: http://msdn.microsoft.com/en-US/data/upgradeEF6

2
  • 1
    is this the answer of your question? Jul 16, 2014 at 16:44
  • Thanks for the suggestion. I just cleaned up my answer. Nov 10, 2014 at 13:47

Your Answer

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

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