I'm following this article to implement repository pattern in a web API project. When implementing the update method in the repository I've followed the example provided, using:
context.Entry<Item>(item).State = System.Data.EntityState.Modified;
For some reason though I'm getting the following build error,
an instance of type system.data.entitystate can not be assigned to a variable of type system.data.entity.entitystate
My code is the same as in the example other than the fact I am using a different entity to the one used in the example. Any ideas why I might be getting this error? I'm using EF 6.02.
Cheers
The error message is very clear, you are using the wrong types, you just need to write:
context.Entry<Item>(item).State = System.Data.Entity.EntityState.Modified;
The System.Data.Entity.EntityState
is living in the EF's EntityFramework.dll
while the System.Data.EntityState
is living in the System.Data.Entity.dll
.
Since EF6 there is no need to reference the System.Data.Entity.dll
(which contains some parts of the EntityFramework which where needed in the previous EF versions).
So you can just remove the System.Data.Entity.dll
reference (which is added automatically by Visual Studio when creating a new project) to avoid these type mismatch errors in the future.