static ProviderMember() { using(InsideWordEntities dbContext = new InsideWordEntities()) { _memberCountIsZero = dbContext.Members.Count() == 0; } }
static ProviderCategory() { // Always check on startup if the root exists. If it doesn't then create it. // Currently the way to check if the root exists is if the table is empty. // We don't currently handle the root being deleted by accident. using (InsideWordEntities dbCtx = new InsideWordEntities()) { if (dbCtx.Categories.Count() == 0) { CreateRoot(dbCtx); } } }
public void DisposeCtx() { _ctx.Dispose(); _ctx = null; }
protected static bool CreateRoot(InsideWordEntities dbCtx) { // Note: The root creation function behaves VERY differently than a normal provider save Category root = new Category(); root.Id = -1; root.SystemCreateDate = DateTime.UtcNow; root.SystemEditDate = DateTime.UtcNow; root.CreateDate = DateTime.UtcNow; root.EditDate = DateTime.UtcNow; root.IsHidden = false; root.Title = "root"; root.ParentCategoryId = null; root.HierarchyLevel = -1; // useful to get all categories in a certain level or check what level this category is on root.FullPath = String.Empty; // used internally by the entity framework and database try { dbCtx.Categories.AddObject(root); dbCtx.SaveChanges(); // Since the categories use triggers to update their hierarchy it is mandatory that a refresh be done on the entity // otherwise the data in HierarchyLevel and FullPath can be incorrect after a save. dbCtx.Refresh(RefreshMode.StoreWins, root); } catch (Exception caughtException) { DbCtx.Instance.Detach(root); throw caughtException; } return true; }