is possible update objects entity framework, without grabbing them first?
example: here, have function provides primary key locate objects, pulls them, updates them. eliminate having pull objects first, , run update query. removing need select query being generated.
public async task<int> updatechecks(long? acctid, string payorname, string checkaccountnumber, string checkroutingnumber, string checkaccounttype) { using (var max = new max(_max.connectionstring)) { var payments = await max.payments.where( w => w.maindatabaseid == acctid && (w.paymentstatus == "pending" || w.paymentstatus == "hold")).tolistasync(); payments.asparallel().forall(payment => { payment.payorname = payorname; payment.checkaccountnumber = checkaccountnumber; payment.checkroutingnumber = checkroutingnumber; payment.checkaccounttype = checkaccounttype; payment.paymentmethod = "check"; payment.paymentstatus = "hold"; }); await max.savechangesasync(); return payments.count; } }
you can use attach()
command attach entity know exists , call savechanges()
will call appropriate update method. here sample code msdn article on topic:
on subject:
var existingblog = new blog { blogid = 1, name = "ado.net blog" }; using (var context = new bloggingcontext()) { context.entry(existingblog).state = entitystate.unchanged; // more work... context.savechanges(); }
note general ef logic, not related specific database implementation.
Comments
Post a Comment