c# - Delete a big list of items with Entity Framework -



c# - Delete a big list of items with Entity Framework -

i want delete big list of items ef, tried remove them 1 1 take long time.

and tried utilize .removeall() method list don't update database [only remove loaded entity]

so utilize sqlcommand remove them database , utilize .removeall() prevent ef unexpected number of rows update (0) exception.

code:

dbcontext.database.executesqlcommand("delete xxx xxx"); loadedentity.subitems.tolist().removeall(r => true); dbcontext.savechanges();

my question: there improve way this?

try

var = dbcontext.xxx.where(x => x.xxx == "xxx"); dbcontext.xxx.removerange(all); dbcontext.savechanges();

c# entity-framework sql-delete

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -