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

  • Home
  • SEARCH
  • 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 6648789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:41:48+00:00 2026-05-26T00:41:48+00:00

How do I map NHibernate type to SQL Server’s TIME type? I’m using NH

  • 0

How do I map NHibernate type to SQL Server’s TIME type? I’m using NH 3.2 and map-by-code.

public class Schedule
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual TimeSpan Time { get; set; }
}

Here is my mapping class

public class ScheduleMapping : ClassMapping<Schedule>
{
    public ScheduleMapping()
    {
        Id(x => x.Id, x => x.Generator(Generators.Native));
        Property(x => x.Name, x => x.NotNullable(true));
        Property(x => x.Time, x => x.NotNullable(true));
    }
}

Now, when I create database from this column “Time” has BIGINT SQL type instead of TIME. I have read this and that article but it’s not clear to me how to apply any of these solutions.

=========== EDIT ====================

I created and inserted new schedule like this:

var newSchedule = new Schedule {
                   Name = "My Schedule",
                   Time = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, 0)
                   };
session.SaveOrUpdate(newSchedule);

When this data was inserted (around 7:27 PM) the Time column contained value ‘700200000000’, which could be ticks, but the most important thing was that when I queried DB for these values

var retrievedSchedules = session.QueryOver<Schedule>().List();

the Time property was properly set to 19:27.Originally I wanted Time property to represent the time at which Schedule is supposed to run. Even though SQL Server’s datatype for this column was defined as BIGINT and the value is represented as (most likely) ticks, after retrieval it was correctly transited into a time, which is what I wanted. This no longer is a question but I’m going to leave this for, hopefully, someone else’s benefit.

  • 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-26T00:41:49+00:00Added an answer on May 26, 2026 at 12:41 am

    This, in your mapping should solve your problem:

    Property(x => x.Time, x => x => { x.NotNullable(true); x.Type<TimeAsTimeSpanType>(); });
    

    By default, NH will use x.Type<TimeSpanType>() as the NH type for the clr Time type … which maps to the SQL Server 2008 as a bigint.

    Have a look here: http://jameskovacs.com/2011/01/26/datetime-support-in-nhibernate/. It covers the different Clr –> NH –> Db type mappings for dates & times.

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

Sidebar

Related Questions

What is the best way to map UInt32 type to sql-server int type with
I am using NH to map c#-double values into SQL Server 2005 as floats.
I'm trying to map java.util.Date to postgresql timestamp without time zone type. I'm using
Please see this post for code example : How to map Type with Nhibernate
I am using the TIME datatype from SQL Server 2008 and I am having
I'm using NHibernate and I map my objects directly with attributes. I've seen similar
I'd like to map the following sql in NHibernate. Will I need to make
Is it possible to map an enum as a string using Fluent Nhibernate?
I am trying to map several tables using Fluent Nhibernate. My tests are giving
I'm trying to map a parent-child relationship using NHibernate (2.1.2), MySql.Data (6.2.2) and MySQL

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.