Entity Framework 6 Cannot build after adding store

2020-05-11 11:33发布

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楼-- · 2020-05-11 12:04

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

查看更多
祖国的老花朵
3楼-- · 2020-05-11 12:27

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.

查看更多
登录 后发表回答