asp.net - I cannot delete or update multiple record using entity framework -
i want delete multiple record using entity framework cannot delete.
i trying following code
db.filetypewithproducts.where(x => x.productid == proid).tolist().foreach(db.filetypewithproducts.deleteobject);
in above statement vs 2013 gives error
error 1 'system.data.entity.dbset<filetypewithproduct>' not contain definition 'deleteobject' , no extension method 'deleteobject' accepting first argument of type 'system.data.entity.dbset<filetypewithproduct>' found (are missing using directive or assembly reference?)
you need use either remove
or removerange
(at least ef6):
db.filetypewithproducts .where(x => x.productid == proid).tolist() .foreach(ft => db.filetypewithproducts.remove(ft)); // need lambda since expected method needs return void.
or:
db.filetypewithproducts .removerange(db.filetypewithproducts.where(x => x.productid == proid).tolist());
Comments
Post a Comment