'Is dbContext.SaveChanges() enough to save all 3 operations, insert, update and delete for multiple tables?

//Say I have below lists:
List<Table1> table1InsertLines;
List<Table1> table1UpdateLinesFromDbContext;//(DbContext.Table1 lines are updated)
List<Table2> table2DeleteLines;
List<Table2> table2InsertLines;
List<Table2> table2UpdateLinesFromDbContext;//(DbContext.Table1 lines are updated)
List<Table1> table1DeleteLines;
//And I do below steps
dbContext.Table1.AddRange(table1InsertLines);
dbContext.Table1.RemoveRange(table2DeleteLines);
dbContext.Table2.AddRange(table1InsertLines);
dbContext.Table2.RemoveRange(table2DeleteLines);
dbContext.SaveChanges();

Is this enough to ensure consistency given that SaveChanges is a transaction itself?



Solution 1:[1]

Yes, the DbContext will keep track of all the changes and ensure to call the Insert, Update and Delete queries when Savechanges is invoked.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1