c# - EntityFramework. Remove all rows then add new. Async -


i'm running csv import sql db via asp.net mvc app.

i'm iterating rows in csv, creating equivalent entity each , adding each 1 current context.

if there @ least 1 row add want remove existing rows table being written to, commit new entities.

my question whether it's safe call executesqlcommandasync , not await result before call await db.savechangesasync(); so:

db.database.executesqlcommandasync("delete tblname"); await db.savechangesasync(); 

or should await delete call before make save changes call? in case may make calls non async versions?

i'm not awaiting , appears working expected on local (practically no latency) i.e. existing data being removed , new data added. concern whether there else should consider when solution deployed , web server , sql server aren't on same box.

as per msdn:

by default, delete statement acquires exclusive (x) lock on table modifies, , holds lock until transaction completes.

this means save action wait until delete action has finished, though latter started async. so, since await save call, in fact await delete call.

i think i'd prefer await delete call explicitly (or don't call async) because might want respond errors raises (like not executing save action writing log instead).

side note: consider using truncate table.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -