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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:50:15+00:00 2026-05-13T20:50:15+00:00

I have a component that i want to store to an SQLite database. public

  • 0

I have a component that i want to store to an SQLite database.

public class Comp : Entity
{
    public virtual DateTime TimeStamp { get; set; }
    public virtual String Name { get; set; }
}

public class CompMap : ClassMap<Comp>
{
    public CompMap()
    {
        Id(x => x.Id);
        Map(x => x.TimeStamp);
        Map(x => x.Name);
    }
}

Nothing fancy really.

The problem is that the TimeStamp is incorrectly stored in the DB (SQLite-Explorer show the value ’30-12-1899′)
I think it has something to do with the way nHibernate sends the DateTime to the database

NHibernate: INSERT INTO "Comp" (TimeStamp, Name) VALUES (@p0, @p1); select last_insert_rowid(); @p0 = 26.02.2010 10:08:09, @p1 = 'test1'

To me it looks like the DateTime is in a string format (might just be the .ShowSQL() command though) and SQLite can’t handle the format (it’s a german datetime formating)
I tried to change the format using an IUserType but the result is still the same.

I’ve not found anyone else having this issue so I’m assuming the problem is in my code but I’m unable to find it.

Here’s the testcode i use to initialize the DB and insert the value to the DB

using System;
using System.IO;
using ConsoleApplication1.db;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var sessionFactory = Fluently.Configure().Database(SQLiteConfiguration.Standard.UsingFile("test.db").ShowSql())
                    .Mappings(m => m.FluentMappings.AddFromAssembly(typeof(Comp).Assembly))
                    .ExposeConfiguration(config =>
                                             {
                                                 if (File.Exists("test.db"))
                                                 {
                                                     File.Delete("test.db");
                                                 }
                                                 new SchemaExport(config)
                                                   .Create(false, true);                                                 
                                             })
                    .BuildSessionFactory(); 
            var session = sessionFactory.OpenSession();
            var ts = DateTime.Now;
            Comp c = new Comp
                         {
                             Name = "test1",
                             TimeStamp = ts
                         };
            session.Save(c);
            session.Flush();
            session.Close();
        }
    }
}

When executing this command and checking the DB Content the TimeStamp doesn’t have the current date/time but 1899-31-12

  • 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-13T20:50:16+00:00Added an answer on May 13, 2026 at 8:50 pm

    Turns out it was indeed my fault plus a profound lack of doublechecking.
    I did write the datetime into the database and then checked the value in the database with sqlite explorer. Apparently that one has issues with DateTime fields and does present an incorrect value.

    That, plus the original program did have a bug (the DateTime wasn’t written properly).

    My conclusion therefor is: Don’t use sqlite explorer

    LinqPad did correctly show the value and will thus be used from now on.

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

Sidebar

Related Questions

No related questions found

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.