I am using Entity framework for building an app.
Table to be updated.
[Id] [CheckItemId] [Checked] [Comment]
1 100 1 abc
2 150 0 xyz
Class:
public class CheckListRequest
{
public int ID { get; set; }
public bool IsChecked { get; set; }
public string Comment { get; set; }
}
public static void UpdateCheckList(List<CheckListRequest> checkList){
}
How do I update the table multiple column like (Checked,comment) with the values coming in list from frontend using LINQ?
Assuming dbContext
is your DataContext
and Id
is the primary key of the table, try this:
public static void UpdateCheckList(List<CheckListRequest> checkList)
{
foreach (CheckListRequest clr in checkList)
{
CheckListRequest clrInDB = dbContext.CheckListRequests.SingleOrDefault(o.Id == clr.Id);
clrInDB.IsChecked = clr.IsChecked;
clrInDB.Comment = clr.Comment;
}
dbContext.SaveChanges();
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments