public static void Initialize(ContactContext context) { context.Database.EnsureCreated(); if (context.Contacts.Any()) { return; } var contacts = ContactsGenerator.GenerateContacts(); context.Contacts.AddRange(contacts); context.SaveChanges(); }
void Initialize() { var contents = string.Empty; if (File.Exists(fullPath)) { contents = File.ReadAllText(fullPath); } if (string.IsNullOrWhiteSpace(contents)) { myContacts = ContactsGenerator.GenerateContacts(); File.WriteAllText(fullPath, contents); } else { myContacts = JsonSerializer.Deserialize <List <Contact> >(contents); } isInitialized = true; }