Entity framework update one column by increasing the current value by one without select

前端 未结 2 1858
刺人心
刺人心 2020-12-30 09:56

What I want to achieve is the simple sql query: UPDATE TABLE SET COLUMN = COLUMN + 1

Is there a way to make it happen without loading all records (t

2条回答
  •  执笔经年
    2020-12-30 10:13

    Here is the solution. You can use the following code:

    context.Table.Where(x => x.Field1 > 0).Update(y => new Table { Field2 = y.Field2 + 1 });
    

    hope that it helps.

提交回复
热议问题