In the code below, I am updating IndexOrder by ID using TryUpdateModel. Below the update, press DB 2 times. After receiving the current record by identifier, than updating one line.
I am using LINQ To EF
foreach (var i in indexArraay)
{
SubMenu existingMenu = _menu.SubSingle(Int32.Parse(i.id.ToString()));
existingMenu.IndexOrder = string.IsNullOrEmpty(i.index.ToString()) ? 0 : Int32.Parse(i.index.ToString());
TryUpdateModel(existingMenu);
_menu.Add();
}
In SQL, we do not do this, as in the instructions below.
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
Am I mistaken somewhere or is there a better way to write an expression for updating LINQ?
I am not talking about performance here.
source
share