예제 #1
0
 static ProviderMember()
 {
     using(InsideWordEntities dbContext = new InsideWordEntities())
     {
          _memberCountIsZero = dbContext.Members.Count() == 0;
     }
 }
예제 #2
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);
         }
     }
 }
예제 #3
0
 public void DisposeCtx()
 {
     _ctx.Dispose();
     _ctx = null;
 }
예제 #4
0
        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;
        }