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 8722821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:29:43+00:00 2026-06-13T07:29:43+00:00

I am using nHibernate + FluentNHibernate with SQLite database. All dates are stored as

  • 0

I am using nHibernate + FluentNHibernate with SQLite database.
All dates are stored as text in format ‘YYYY-MM-DD HH:MM:SS’

How can I instruct nHibernate (or sqlite driver???) to truncate time part and store date in ‘YYYY-MM-DD’ format for certain fields (and storing the full date for other fields) ?

Or how can I instruct to store all dates as integers ?

I am concerned on space usage, because dates takes a lot of space in the database and there are indexes on dates too, so I need to make them taking as less space as possible.

  • 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-06-13T07:29:44+00:00Added an answer on June 13, 2026 at 7:29 am

    If you convert DateTime to String manually, I can’t see any problem to replace string format by YYYY-MM-DD.

    If you let NHibernate to perform this conversion, then you could create custom NHibernate UserType like so:

    public abstract class DateTimeAsStringType : IUserType
    {
        public object Assemble(object cached, object owner)
        {
            return cached;
        }
    
        public object DeepCopy(object value)
        {
            return value;
        }
    
        public object Disassemble(object value)
        {
            return value;
        }
    
        public bool Equals(object x, object y)
        {
            if (ReferenceEquals(x, y))
                return true;
    
            if (x == null && y == null)
                return false;
    
            return x.Equals(y);
        }
    
        public int GetHashCode(object x)
        {
            return x.GetHashCode();
        }
    
        public bool IsMutable
        {
            get { return false; }
        }
    
        public object NullSafeGet(System.Data.IDataReader rs, string[] names, object owner)
        {
            var serialized = NHibernateUtil.String.NullSafeGet(rs, names[0]) as string;
    
            if (string.IsNullOrEmpty(serialized))
                return null;
    
            return Deserialize(serialized);
        }
    
        protected abstract DateTime Deserialize(string value);
        protected abstract string Serialize(DateTime value);
    
        public void NullSafeSet(System.Data.IDbCommand cmd, object value, int index)
        {
            if (value == null)
                NHibernateUtil.String.NullSafeSet(cmd, DBNull.Value, index);
            else
                NHibernateUtil.String.NullSafeSet(cmd, Serialize((DateTime)value), index);
        }
    
        public object Replace(object original, object target, object owner)
        {
            return original;
        }
    
        public Type ReturnedType
        {
            get { return typeof(DateTime); }
        }
    
        public NHibernate.SqlTypes.SqlType[] SqlTypes
        {
            get { return new[] { NHibernateUtil.String.SqlType }; }
        }
    }
    
    public class TruncatedDateTimeAsStringType : DateTimeAsStringType
    {
        private const string Format = "yyyy-MM-dd";
    
        protected override string Serialize(DateTime value)
        {
            return value.ToString(Format, CultureInfo.InvariantCulture);
        }
    
        protected override DateTime Deserialize(string value)
        {
            return DateTime.ParseExact(value, Format, CultureInfo.InvariantCulture, DateTimeStyles.None);
        }
    }
    
    public class FullDateTimeAsStringType : DateTimeAsStringType
    {
        private const string Format = "yyyy-MM-dd hh:mm:ss";
    
        protected override string Serialize(DateTime value)
        {
            return value.ToString(Format, CultureInfo.InvariantCulture);
        }
    
        protected override DateTime Deserialize(string value)
        {
            return DateTime.ParseExact(value, Format, CultureInfo.InvariantCulture, DateTimeStyles.None);
        }
    }
    

    And map your DateTime property using either TruncatedDateTimeAsStringType or FullDateTimeAsStringType:

    <property name="TruncatedDateTime" type="Your.Namespance.TruncatedDateTimeAsStringType, Your.Assembly" />
    <property name="NotTruncatedDateTime" type="Your.Namespance.FullDateTimeAsStringType, Your.Assembly" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF Application using Fluent NHibernate 1.0 RTM and System.Data.SQLite 1.0.65 that
I think this is a moderately neophyte question. I've been using NHibernate/FluentNHibernate for about
I am using NHibernate with FluentNHibernate for my DAL. I am also using SchemaExport
I'm using FluentNHibernate but NHibernate XML will do. Say I have this model public
I am using NHibernate/Fluent NHibernate in an ASP.NET MVC app with a MySQL database.
I'm using Fluent NHibernate auto mapping. I need to access more than one database
I have a WPF application running with VS2010 .Net3.5 using Nhibernate with FluentNHibernate +
I'm using SQLite ( system.data.sqlite v. 1.0.60.0 ) on a Fluent NHibernate project. I
Is there a way to setup SQLite connection pooling using Fluent NHibernate configuration? E.g.
In my project I am using NHibernate/FluentNHibernate, and I am working with two entities,

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.