Entity Framework 5.0 - Delete object without retrieving it -


i want delete database entry this:

public bool deletepersonbyid(int id)     {         var p = new person() { id = id };         //ctx.person.attach(p);         ctx.entry<person>(p).state = entitystate.deleted;         return true;     } 

then invalidoperationexception following message:

the key field 'firstname' cannot have value of null. non-null value required key fields defined on type 'person'.

so, me doesn't matter if property can or cannot null in case, because want delete complete row/object. object loaded asnotracking()

(from p in ctx.person.asnotracking() p.id == id select p).firstordefault(); 

ok, table didn't have primary key, after adding pk on db table , regenerating ef model, above code works.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -