private async static void createData(DemoContext db) { if (db.Users.Count() == 0) { var u = new User { Firstname = "Michael", Lastname = "Prattinger", Username = "******" }; db.Users.Add(u); u = new User { Firstname = "Lilly", Lastname = "Prattinger", Username = "******" }; db.Users.Add(u); u = new User { Firstname = "Sophie", Lastname = "Prattinger", Username = "******" }; db.Users.Add(u); u = new User { Firstname = "Mia", Lastname = "Prattinger", Username = "******" }; db.Users.Add(u); await db.SaveChangesAsync(); } }
static void Main(string[] args) { using (var db = new DemoContext()) { createData(db); Console.WriteLine("Users:"); Console.WriteLine("======"); db.Users.ToList().ForEach(u => { Console.WriteLine($"Username: {u.Username}, Name: {u.Firstname} {u.Lastname}"); }); } Console.WriteLine("Press any key..."); Console.ReadKey(); }