Answers for "dotnet core ef add multiple records"

C#
0

dotnet core ef add multiple records

 
using (EFCoreContext db = new EFCoreContext())
{
    List<Department> deps = new List<Department>();
 
    deps.Add(new Department { Name = "Dept1", Descr = "" });
    deps.Add(new Department { Name = "Dept2", Descr = "" });
 
    db.Departments.AddRange(deps);
    db.SaveChanges();
}
 
//SQL Command
INSERT INTO [Departments] ([Descr], [Name])
VALUES (@p0, @p1);
 
SELECT [DepartmentID]
FROM [Departments]
WHERE @@ROWCOUNT = 1 AND [DepartmentID] = scope_identity();
          
INSERT INTO [Departments] ([Descr], [Name])
VALUES (@p0, @p1);
         
SELECT [DepartmentID]
FROM [Departments]
WHERE @@ROWCOUNT = 1 AND [DepartmentID] = scope_identity();
 
Posted by: Guest on April-13-2022

C# Answers by Framework

Browse Popular Code Answers by Language