public override void DeleteCategory(ICategory category)
        {
            if (category == null)
                throw new ArgumentNullException("category");

            ICategory c = GetCategory(category.ID);

            if (c == null)
                return;

            LinqCategory item = new LinqCategory()
            {
                ApplicationName = this.ApplicationName,
                DateCreated = category.DateCreated,
                ID = category.ID,
                LastUpdated = category.LastUpdated,
                Name = category.Name,
                ParentID = category.Parent != null ? category.Parent.ID : default(Nullable<Guid>)
            };

            using (ContentManagerDataContext db = new ContentManagerDataContext(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString))
            {
                Table<LinqCategory> categories = db.GetTable<LinqCategory>();

                // Set to false to indicate that the object does not have a timestamp (RowVersion)
                categories.Attach(item, true);

                categories.DeleteOnSubmit(item);

                try
                {
                    db.SubmitChanges(ConflictMode.ContinueOnConflict);
                }
                catch (ChangeConflictException ex)
                {
                    Trace.TraceError(ex.Message);

                    // All database values overwrite current values.
                    foreach (ObjectChangeConflict occ in db.ChangeConflicts)
                        occ.Resolve(RefreshMode.OverwriteCurrentValues);
                }
                catch (System.Data.Common.DbException ex)
                {
                    Trace.TraceError(ex.Message);
                }
            }
        }
        public override void UpdateCategory(ICategory category)
        {
            if (category == null)
                throw new ArgumentNullException("category");

            ICategory c = GetCategory(category.ID);

            if (c == null)
                throw new ChangeConflictException("Category not found or deleted");

            LinqCategory item = new LinqCategory()
            {
                ApplicationName = this.ApplicationName,
                DateCreated = category.DateCreated,
                ID = category.ID,
                LastUpdated = c.LastUpdated,
                Name = category.Name,
                ParentID = category.Parent != null ? category.Parent.ID : default(Nullable<Guid>)
            };

            using (ContentManagerDataContext db = new ContentManagerDataContext(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString))
            {
                Table<LinqCategory> categories = db.GetTable<LinqCategory>();

                // Assume that "page" has been sent by client.
                // Attach with "true" to the change tracker to consider the entity modified
                // and it can be checked for optimistic concurrency because
                // it has a column that is marked with "RowVersion" attribute
                categories.Attach(item, true);

                try
                {
                    db.SubmitChanges(ConflictMode.ContinueOnConflict);
                }
                catch (ChangeConflictException ex)
                {
                    Trace.TraceError(ex.Message);

                    // All database values overwrite current values.
                    foreach (ObjectChangeConflict occ in db.ChangeConflicts)
                        occ.Resolve(RefreshMode.OverwriteCurrentValues);
                }
                catch (System.Data.Common.DbException ex)
                {
                    Trace.TraceError(ex.Message);
                }
            }
        }
        public override void InsertCategory(ICategory category)
        {
            if (category == null)
                throw new ArgumentNullException("category");

            LinqCategory c = new LinqCategory()
            {
                ApplicationName = this.ApplicationName,
                DateCreated = category.DateCreated,
                ID = category.ID,
                LastUpdated = category.LastUpdated,
                Name = category.Name,
                ParentID = category.Parent != null ? category.Parent.ID : default(Nullable<Guid>)
            };

            using (ContentManagerDataContext db = new ContentManagerDataContext(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString))
            {
                Table<LinqCategory> categories = db.GetTable<LinqCategory>();

                categories.InsertOnSubmit(c);

                try
                {
                    db.SubmitChanges(ConflictMode.ContinueOnConflict);
                }
                catch (ChangeConflictException ex)
                {
                    Trace.TraceError(ex.Message);

                    // All database values overwrite current values.
                    foreach (ObjectChangeConflict occ in db.ChangeConflicts)
                        occ.Resolve(RefreshMode.OverwriteCurrentValues);
                }
                catch (System.Data.Common.DbException ex)
                {
                    Trace.TraceError(ex.Message);
                }
            }
        }
        private void ReadContentManagerStore()
        {
            if (!_isInitialized)
                throw new InvalidOperationException("Provider has not been initialized");

            if (_categories == null)
            {
                lock (syncRoot)
                {
                    if (_categories == null)
                    {
                        _categories = new Dictionary<Guid, LinqCategory>();
                        _sections = new Dictionary<Guid, LinqSection>();
                        _pages = new Dictionary<Guid, LinqPage>();
                        _roles = new NameValueCollection();
                        _modules = new Dictionary<Guid, LinqModule>();

                        XmlDocument doc = new XmlDocument();
                        doc.Load(_xmlFileName);

                        #region Categories

                        XmlNodeList nodes = doc.GetElementsByTagName("Category");

                        foreach (XmlNode node in nodes)
                        {
                            LinqCategory category = null;

                            Guid id = new Guid(node["ID"].InnerText);

                            if (_categories.ContainsKey(id))
                            {
                                category = _categories[id];
                            }
                            else
                            {
                                category = new LinqCategory(id);
                                _categories.Add(id, category);
                            }

                            category.Name = node["Name"].InnerText;

                            if (!string.IsNullOrEmpty(node["DateCreated"].InnerText))
                                category.DateCreated = DateTime.Parse(node["DateCreated"].InnerText);
                            if (!string.IsNullOrEmpty(node["LastUpdated"].InnerText))
                                category.LastUpdated = DateTime.Parse(node["LastUpdated"].InnerText);

                            if (!string.IsNullOrEmpty(node["ParentID"].InnerText))
                                category.ParentID = new Guid(node["ParentID"].InnerText);
                        }

                        #endregion

                        #region Sections

                        nodes = doc.GetElementsByTagName("Section");

                        foreach (XmlNode node in nodes)
                        {
                            LinqSection section = null;

                            Guid id = new Guid(node["ID"].InnerText);

                            if (_sections.ContainsKey(id))
                            {
                                section = _sections[id];
                            }
                            else
                            {
                                section = new LinqSection(id);
                                _sections.Add(id, section);
                            }

                            section.Name = node["Name"].InnerText;
                            section.Index = Int32.Parse(node["Index"].InnerText);
                            section.Slug = node["Slug"].InnerText;
                            if (!string.IsNullOrEmpty(node["DateCreated"].InnerText))
                                section.DateCreated = DateTime.Parse(node["DateCreated"].InnerText);
                            if (!string.IsNullOrEmpty(node["LastUpdated"].InnerText))
                                section.LastUpdated = DateTime.Parse(node["LastUpdated"].InnerText);
                            section.IsVisible = bool.Parse(node["IsVisible"].InnerText);

                            if (!string.IsNullOrEmpty(node["ParentID"].InnerText))
                                section.ParentID = new Guid(node["ParentID"].InnerText);

                            XmlNodeList roles = node.SelectNodes("./Roles/Role");

                            foreach (XmlNode role in roles)
                                _roles.Add(section.ID.ToString(), role.InnerText);
                        }

                        #endregion

                        #region Pages

                        nodes = doc.GetElementsByTagName("Page");

                        foreach (XmlNode node in nodes)
                        {
                            LinqPage page = null;

                            Guid id = new Guid(node["ID"].InnerText);

                            if (_pages.ContainsKey(id))
                            {
                                page = _pages[id];
                            }
                            else
                            {
                                page = new LinqPage(id);
                                _pages.Add(id, page);
                            }

                            page.Title = node["Title"].InnerText;
                            page.Slug = node["Slug"].InnerText;
                            page.Description = node["Description"].InnerText;
                            page.Keywords = node["Keywords"].InnerText;
                            page.Layout = node["Layout"].InnerText;
                            if (!string.IsNullOrEmpty(node["DateCreated"].InnerText))
                                page.DateCreated = DateTime.Parse(node["DateCreated"].InnerText);
                            if (!string.IsNullOrEmpty(node["LastUpdated"].InnerText))
                                page.LastUpdated = DateTime.Parse(node["LastUpdated"].InnerText);
                            page.IsVisible = bool.Parse(node["IsVisible"].InnerText);
                            page.Author = node["Author"].InnerText;
                            page.LastUpdatedBy = node["LastUpdatedBy"].InnerText;

                            if (!string.IsNullOrEmpty(node["ParentID"].InnerText))
                                page.ParentID = new Guid(node["ParentID"].InnerText);

                            if (!string.IsNullOrEmpty(node["SectionID"].InnerText))
                                page.SectionID = new Guid(node["SectionID"].InnerText);

                            XmlNodeList roles = node.SelectNodes("./Roles/Role");

                            foreach (XmlNode role in roles)
                                _roles.Add(page.ID.ToString(), role.InnerText);
                        }

                        #endregion
                    }
                }
            }
        }