Efcore: Add Update Method to DbSet

Created on 4 Feb 2019  路  3Comments  路  Source: dotnet/efcore

Why not add Update method to DbSet class
Method Signature: DbSet.Update(Func predicate, T);
So to update a row in a table:
Employee employee = new Employee{FirstName = "Mohamed"};
context.Employees.Update(x => x.Id == 1, employee);
this line should produce this sql statement: update Employee set FirstName = 'Mohamed' where Id = 1;
If for example, user want to update multiple rows this method will help him/her.
example: context.Employees.Update(x => 1 == 1, new Employee{DepartmentId= 1});
this line should produce this sql statement: update Employee set DepartmentId = 1 where 1 =1;

closed-duplicate customer-reported

Most helpful comment

EF core should have more functionalities for C/U/D operations without using change tracker - directly composing and execution the query. Most of the times we don't need the change-tracker. It only adds overhead.

All 3 comments

EF core should have more functionalities for C/U/D operations without using change tracker - directly composing and execution the query. Most of the times we don't need the change-tracker. It only adds overhead.

Many developers use AsNoTracking method and as you said most of the times we don't need change tracker, so these types of C/U/D operations should be implemented

Duplicate of #795

Was this page helpful?
0 / 5 - 0 ratings