问题
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