Skip to content

Instantly share code, notes, and snippets.

@executeautomation
Created August 15, 2021 10:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save executeautomation/36bb37d208423d738ba6e9fb468f7b8f to your computer and use it in GitHub Desktop.
Save executeautomation/36bb37d208423d738ba6e9fb468f7b8f to your computer and use it in GitHub Desktop.
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