c# - Delete a single record from Entity Framework? -


(reworded)

i have sql server table in entity framework named employ single key column named id.

how delete single record table using entity framework?

it's not necessary query object first, can attach context id. this:

var employer = new employ { id = 1 }; ctx.employ.attach(employer); ctx.employ.remove(employer); ctx.savechanges(); 

alternatively, can set attached entry's state deleted *thanks simon belanger *:

var employer = new employ { id = 1 }; ctx.entry(employer).state = entitystate.deleted; ctx.savechanges(); 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -