Created
August 15, 2021 10:07
-
-
Save executeautomation/36bb37d208423d738ba6e9fb468f7b8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataSeeder | |
{ | |
private readonly EmployeeDbContext employeeDbContext; | |
public DataSeeder(EmployeeDbContext employeeDbContext) | |
{ | |
this.employeeDbContext = employeeDbContext; | |
} | |
public void Seed() | |
{ | |
if(!employeeDbContext.Employee.Any()) | |
{ | |
var employees = new List<Employee>() | |
{ | |
new Employee() | |
{ | |
Name = "Karthik", | |
Citizenship = "India", | |
EmployeeId = "1" | |
}, | |
new Employee() | |
{ | |
Name = "Jacob", | |
Citizenship = "US", | |
EmployeeId = "2" | |
} | |
}; | |
employeeDbContext.Employee.AddRange(employees); | |
employeeDbContext.SaveChanges(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment