refresh dbset entity from database code example
Example 1: insert multiple records on the Database in Entity Framework Core
var dept1 = new Department() { Name = "Development" };
var dept2 = new Department() { Name = "HR" };
var dept3 = new Department() { Name = "Marketing" };
using (var context = new CompanyContext())
{
context.Department.AddRange(dept1, dept2, dept3);
context.SaveChanges();
}
Example 2: Update data in db .net
var query =
from ord in db.Orders
where ord.OrderID == 11000
select ord;
foreach (Order ord in query)
{
ord.ShipName = "Mariner";
ord.ShipVia = 2;
}
try
{
db.SubmitChanges();
}
catch (Exception e)
{
Console.WriteLine(e);
}