Generated.Insert() on DateTime in SQL Server is not generating on INSERT

Original Post ScottM's Avatar

ScottM

11 May, 2010 01:28 PM via web

Forehead is bloody from trying to get this mapping to generate the datetime on INSERT:

public class InstanceMap : ClassMap
{ Id(x => x.Id, "Id").GeneratedBy.GuidComb(); Map(x => x.CreatedBy); Map(x => x.CreatedOn).Generated.Insert(); Map(x => x.ModifiedBy); Map(x => x.ModifiedOn).Generated.Always(); Map(x => x.Description).Length(100); ...

I'm using FluentNHibernate 1.0.0.593 and NHibernate 2.1.0.4.

  1. Support Staff 2 Posted by Paul Batum on 17 May, 2010 04:47 AM

    Paul Batum's Avatar

    Simply telling nhibernate that the particular property is generated on insert is not enough to actually get the current date and time saved into the column. The responsibility of generating the value lies with the DB. Generated.Insert just tells NH that it should perform a select to reload the object after its performed an insert.

    http://www.nhforge.org/doc/nh/en/#mapping-generated

  2. Support Staff 3 Posted by Paul Batum on 18 May, 2010 12:02 PM

    Paul Batum's Avatar

    Hey, thats cool, I didn't know about Default. Nice one.

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What is two plus two?