Consider the following simple C # class:
public class Entity
{
public Entity() { }
public virtual int Id { get; private set; }
public virtual DateTime DateCreated { get; private set; }
}
Displayed in the following simple NHibernate display:
<class name="Entity" mutable="false">
<id name="Id">
<generator class="native">
</id>
<property name="DateCreated"/>
</class>
To the following simple database schema:
CREATE TABLE Entity (
Id int IDENTITY(1,1) PRIMARY KEY,
DateCreated datetime NOT NULL DEFAULT getUtcDate()
)
When creating a new instance Entityand saving to the database, how do you instruct NHibernate to use the default database value for the column DateCreatedif its value is equal null? Alternatively, how can I indicate that NHibernate should use the result of the function getUtcDate()as the value for the field DateCreatedwhen pasting?
So far I could easily add
DateCreated = DateTime.Now;
Entity, , , , .