public WebPage Rollback(int pageID, int version) { var page = Find(pageID); if (!page.EnableVersioning) { throw new Exception("The web page is not enable version controll.Roll back fail."); } if (page.Version == version) { throw new Exception("Can not roll back to current version"); } var pageVer = context.Set <WebPageVersion>().FirstOrDefault(v => v.PageID == pageID && v.Version == version); if (pageVer == null) { throw new Exception("The web page version not found."); } Context.Database.ExecuteSqlCommand("DELETE FROM dna_Widgets WHERE PageID={0}"); Context.Database.ExecuteSqlCommand("DELETE FROM dna_WebPageVersions WHERE PageID={0} AND Version<{1}", pageID, version); PageElement pageData = null; if (!string.IsNullOrEmpty(pageVer.Content)) { pageData = (PageElement)XmlSerializerUtility.DeserializeFromXmlText <PageElement>(pageVer.Content); page.Populate(pageData); var widgetDatas = pageData.Widgets; foreach (var w in widgetDatas) { var descroptor = Context.WidgetDescriptors.FirstOrDefault(d => d.InstalledPath.Equals(w.WidgetID, StringComparison.OrdinalIgnoreCase)); if (descroptor != null) { var widget = new WidgetInstance(); widget.Popuple(w); widget.PageID = page.ID; widget.WebPage = page; widget.DescriptorID = descroptor.ID; widget.WidgetDescriptor = descroptor; Context.Widgets.Add(widget); } } } page.LastModified = DateTime.Now; page.Version = pageVer.Version; Context.SaveChanges(); return(page); }