码迷,mamicode.com
首页 > 其他好文 > 详细

报错:无法将类型"System.Data.EntityState"隐式转换为"System.Data.Entity.EntityState"

时间:2015-07-06 13:59:18      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

 报错:无法将类型"System.Data.EntityState"隐式转换为"System.Data.Entity.EntityState"

原因一:

 

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;

是否引用了System.Data.Entity   是则:db.Entry<UserInfo>(entity).State =EntityState.Deleted;

                                               否则加上db.Entry<UserInfo>(entity).State = System.Data.EntityState.Deleted;

加上命名空间

原因二:

 

出错语句停留在:DataContext.Entry(entity).State = EntityState.Modified; 
从语法上看没有什么错误。DataContext是在Model层通过添加edmx自动生成的,而出错语句所在的数据层安装了最新版的Entity Framework,我们知道:在edmx中创建实体导入数据库的时候,VS也会为我们自动装上Entity Framework,是否此处的EF版本和数据层不一样呢?

 

解决方法

 

先卸载EF:Uninstall-Package EntityFramework -Force 
在安装EF5.0:Install-Package EntityFramework –Version 5.0.0

 

报错:无法将类型"System.Data.EntityState"隐式转换为"System.Data.Entity.EntityState"

标签:

原文地址:http://www.cnblogs.com/luwei19911206/p/4624046.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!