c# - EF: Increase a field by X -
i want increase quantity
property of stock
entity x
units 10. effort using ef fails because appropriate sql statement (quantity = quantity + 10
) not generated , instead (quantity = 110
) generated. important in concurrent model;
var db = new warehousecontext(); stock s = db.stocks.single(p=>p.id==1); console.writeline(s.quantity); // --> 100 s.quantity += 10; db.savechanges();
this generates:
update dbo.stock set quantity = 110;
but, want this:
update dbo.stock set quantity = quantity + 10;
Comments
Post a Comment