entity framework - How to update a field using its own value with only one query? -
considering folling query:
update t1 set p1 = p1 + 10 id = @id
how can achieve same behaviour in entityframework 1 query?
currently, doing this:
var obj = bd.objs.single<objclass>(x=> x.id == id); obj.p1 = obj.p1 + 10; bd.savechanges();
but wastes db access querying object
well, there way it, need use 3rd party library (entity framework extended library)
context.objs .where(t => t.id== id) .update(t => new obj{ p1= t.p1+10 });
this nuget package need install. library eliminates need retrieve , load entity before modifying it. can use delete or update entities.
Comments
Post a Comment