Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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();
 
Source by www.tektutorialshub.com #
 
PREVIOUS NEXT
Tagged: #dotnet #core #ef #add #multiple #records
ADD COMMENT
Topic
Name
6+6 =