Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 296065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:30:52+00:00 2026-05-12T06:30:52+00:00

How do I configure NHibernate to create the db schema with a column like

  • 0

How do I configure NHibernate to create the db schema with a column like this:

create_dt datetime not null default getdate()

I have this in the mapping file:

<property name="create_dt" update="false" insert="false" generated="insert" not-null="true" />

Is there anyway I can inject the sql server specific default getdate(). The documentation for generated properties even mentions this is how you handle a create_date field. I’m just not sure how to make my db schema generate properly. Will I have to edit the create table scripts manually?

Similar question.

EDIT: I figured out I can always change the table schema like so:

<database-object>
    <create>ALTER TABLE Report ADD CONSTRAINT DF_report_create_dt DEFAULT getdate() FOR create_dt;</create>
    <drop></drop>
  </database-object>

and I could add a trigger in the same way for an update_dt type of field. This seems better than supplying explicit insert and update statements that use getdate().

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:30:53+00:00Added an answer on May 12, 2026 at 6:30 am

    I alway prefer to use the NHibernate Event system to set my audit properties like created date or update date. (See event system documentation here).

    I prefer this approach because it keeps the logic out of my database layer but also it gives me the ability to have a single location in my code that is responsible for setting these values. And if I have a common base class for all my entities then I can even guarantee consistent behavior throughout my domain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to configure Hiberate/NHibernate not to use the default constructor to create
I used schemaExport to create my tables like this Configuration config = new Configuration();
I am assuming nhibernate can handle circular reference issues as I have not seen
This is how I create Session Factory using Fluent Nhibernate public static ISessionFactory CreateSessionFactory()
I am using NHibernate in my web application. So far I have created this
Using C#4.0 Following on from my question How to configure nHibernate for many-many mapping?
I have a Fluent NHibernate Mapping that maps a property of a class to
I have a WCF service using NHibernate, I am trying to connect this WCF
I'm trying to configure nhibernate 2.1.2 to run in medium trust, without any luck.
I've spent some time searching around how to configure NHibernate's FlushMode so it could

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.