'EntityState' is an ambiguous reference between 'System.Data.EntityState' and 'System.Data.Entity.EntityState'

一个人想着一个人 提交于 2021-02-07 08:47:34

问题


I'm getting the error

'EntityState' is an ambiguous reference between 'System.Data.EntityState' and 'System.Data.Entity.EntityState'

I'm getting this error on my 4 controllers using mvc5 entity framework.

The line in question is db.Entry(director).State = EntityState.Modified;

Same on each controller just different models.


回答1:


Simply provide the fully-qualified EntityState depending on whichone you want:

db.Entry(director).State = System.Data.EntityState.Modified;

or

db.Entry(director).State = System.Data.Entity.EntityState.Modified;



回答2:


There is two namespace added in your controller named System.Data and System.Data.Entity and both has EntityState property. Compiler is confusing here and gives you the ambiguous reference error. You need to specify the property with the namespace like

db.Entry(director).State = System.Data.Entity.EntityState.Modified; 



回答3:


You should use System.Data.Entity.EntityState instead of System.Data.EntityState.



来源:https://stackoverflow.com/questions/40939961/entitystate-is-an-ambiguous-reference-between-system-data-entitystate-and-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!