Search code examples
asp.net-mvcerror-handlingef-database-firstusing-statement

'object' does not contain a definition for 'State'


I encounter this error in my project:

Error CS1061 'object' does not contain a definition for 'State' and no extension method 'State' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

This error cause to fail of Update and Delete queries.because of this lines:

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

I guess, the specific library or reference is cleaned.
Can you guide me.


Solution

  • You can try db.SaveChanges() for update entity and .Remove(entity) for delete entity.