Using FNH w / SQL Server 2008, I am trying to add the version as a timestamp, but it works in the SQLDateTime Overflow error because the value is passed as 1/1/0001 12:00:00 AM. I found this (also mentioned here ), but still experiencing a problem.
// entity base public abstract class EntityBase { public virtual Int64 Id { get; set; } public virtual DateTime Version { get; set; } } // entity base map public abstract class EntityBaseMap<T> : ClassMap<T> where T : EntityBase { public EntityBaseMap() { Id(x => x.Id).GeneratedBy.Identity(); OptimisticLock.Version(); Version(x => x.Version) .CustomType("Timestamp"); } }
SQL Server data type "datetime".
I suppose this is something small and stupid, but have not yet found a reason - what am I missing?
EDIT: Action method for the actual save code
public ActionResult Create() { int currMaxSortOrder = session.CreateCriteria(typeof(Section)) .SetProjection(Projections.ProjectionList().Add(Projections.Max("Sortorder"))) .UniqueResult<int>(); SectionViewModel sectionViewModel = new SectionViewModel(); sectionViewModel.Sortorder = currMaxSortOrder + 1; return View("Create", "_AdminLayout", sectionViewModel); } [HttpPost] public ActionResult Create(SectionViewModel sectionInputModel) { if (ModelState.IsValid) { section = new Section(); Mapper.Map(sectionInputModel, section); using (var tx = session.BeginTransaction()) { session.SaveOrUpdate(section); tx.Commit(); } return RedirectToAction("index", "pages").WithFlash(new { success = "Section '" + section.Name + "' was successfully added." }); } return View("Create", "_AdminLayout", section); }
Edit 2: Added object and section display
public class Section : EntityBase { public virtual String Name { get; set; } public virtual int Sortorder { get; set; } public virtual String RedirectUrl { get; set; } public virtual IList<Page> Pages { get; set; } public Section() { Pages = new List<Page>(); } public virtual void AddPage(Page page) { page.Section = this; this.Pages.Add(page); } } public class SectionMap : EntityBaseMap<Section> { public SectionMap() { Map(x => x.Name); Map(x => x.Sortorder); Map(x => x.RedirectUrl);
source share