public static void InitializeOverwrite(SLICKIceDBContext context) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); // add test accounts // Account[] accounts = generateTestAccounts(); // foreach (Account a in accounts) // { // context.Add(a); // } // context.SaveChanges(); // add test items Item[] items = generateTestItems(); foreach (Item i in items) { context.Add(i); } context.SaveChanges(); // add test inventory // Inventory[] inventory = generateTestInventory(); // foreach (Inventory i in inventory) // { // context.Add(i); // } // context.SaveChanges(); }
public static bool Initialize(SLICKIceDBContext context) { context.Database.EnsureCreated(); bool anyItems = false; bool dbInitialized = true; // look for any items try { var accountRecords = context.Item.FromSql("SELECT * FROM Item").ToList(); if (accountRecords.Any()) { anyItems = true; } // add some if none available if (!anyItems) { // add test accounts // Account[] accounts = generateTestAccounts(); // foreach (Account a in accounts) // { // context.Add(a); // } // context.SaveChanges(); // add test items Item[] items = generateTestItems(); foreach (Item i in items) { context.Add(i); } context.SaveChanges(); // add test inventory // Inventory[] inventory = generateTestInventory(); // foreach (Inventory i in inventory) // { // context.Add(i); // } // context.SaveChanges(); } } catch (Exception) { dbInitialized = false; } return(dbInitialized); }