.net - Is it possible to execute an efficient multiple row DELETE or UPDATE using EF4? -
i'm developer still learning intricacies of ef4. aware of how pull down list of objects , iterate through deleting them in loop can't bring myself write code execute n statements (and database round-trips) n records when doing mass update or delete.
a classic case deleting child records prior deleting related parent record maintain referential integrity... (yes, employ soft deletes default humor me)
in stored procedure i'd execute sql, so:
delete somechildtable foreigntableid = @keytogo delete parenttable id = @keytogo
in linq sql this:
datacontext.childrentable.deleteallonsubmit(from c in datacontext.childrentable c.parenttableid == keytogo select c); datacontext.parenttable.deleteonsubmit(parenttogo); datacontext.submitchanges();
in nhibernate this:
nhsession.createquery("delete childrentable parenttable.id = :keytogo") .setint32("keytogo", keytogo) .executeupdate(); nhsession.delete(parenttogo);
i've looked ef equivalent of these without success. must drop stored procedure within context of ef4? hope not; please share.
ef orm - object-relational mapper. it's great @ mapping rows , columns relational database .net object model - , works best reading, inserting, updating 1 or few objects.
ef not designed , intended tool handle large operations, it's not designed , optimized batch updates, batch deletes etc. handled better either using straight ado.net execute t-sql commands against database, or calling stored procedure work.
so in situation, create stored procedure handle delete operation, , import stored proc ef model can call method on entitycontext , let sql server heavy lifting.
Comments
Post a Comment