问题描述
为了回应Slauma对我的问题的回答,我将应用程序从Entity Framework 5.0转换为使用Entity Framework 5.0和目标框架.NET 4.0(也称为实体框架4.4)
In response to Slauma's answer to my question about running applications that use EF on Windows XP I am converting my application back from Entity Framework 5.0 to use Entity Framework 5.0 and target framework .NET 4.0 (Also called Entity Framework 4.4)
但是我遇到以下错误;
However I encounter the following error;
System.Data.Entity.DbSet<MyEntity> does not contain a definition for AddOrUpdate
and no extension method of a type System.Data.Entity.DbSet<MyEntity> accepting a
first argument of type System.Data.Entity.DbSet<MyEntity> could be found.
(Are you missing a using directive or assembly reference )
我尝试搜索片段的错误信息,但没有太大的成功。
奇怪的是,甚至没有提到甚至不是EF4.4的SO标签
I have tried searching on fragments of this error message, but am not having much success.Strangely 4.4 isn't even mentioned in this Microsoft link There isn't even an SO tag for EF4.4
推荐答案
你必须添加...
using System.Data.Entity.Migrations;
...到您的代码文件中有 AddOrUpdate
可用。它是扩展方法 System.Data.Entity.Migrations中的 IDbSetExtensions
类中实现的IDbSet< T> 命名空间。
...to your code file to have AddOrUpdate
available. It is an extension method of IDbSet<T>
that is implemented in the IDbSetExtensions
class in System.Data.Entity.Migrations
namespace.
这篇关于如何在Entity Framework 4.4中实现DBSet.AddOrUpdate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!