asp.net mvc - Version as timestamp in Fluent NHibernate / SQL Server -


using fnh w/ sql server 2008, i'm trying add version timestamp, running sqldatetime overflow error because value passed 1/1/0001 12:00:00 am. found this (also referenced here), still experiencing 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> t : entitybase {     public entitybasemap()     {         id(x => x.id).generatedby.identity();         optimisticlock.version();         version(x => x.version)            .customtype("timestamp");      } }     

the sql server data type "datetime".

i'm guessing small , stupid, haven't found cause yet - missing?

edit: action method 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 + "' added." });         }         return view("create", "_adminlayout", section);     } 

edit 2: added section entity & mapping

    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);             // 1 many relationship             hasmany(x => x.pages)                 .inverse()                 .cascade.all();         }     } } 

sheepish doh! moment

(adding in case other n00bs me run same problem)

i dug deeper , realized had configured use automapping while creating maps work fluentmapping. reverted use fluentmapping , version started working perfectly!

i'm guessing possibly use automapping , add convention treat column named "version" customtype("timestamp"), going use fluentmapping until more speed.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -