I have a component that I want to store in a 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 special.
The problem is that TimeStampit is stored incorrectly in the database (SQLite-Explorer shows the value "30 -12-1899") I think this has something to do with how nHibernate sends DateTimeto the database
NHibernate: INSERT INTO "Comp" (TimeStamp, Name) VALUES (@p0, @p1); select last_insert_rowid(); @p0 = 26.02.2010 10:08:09, @p1 = 'test1'
It seems to me that it DateTimeis in a string format (maybe it's just a command .ShowSQL()), and SQLite cannot handle the format (this is the German datetime formation) I tried to change the format with IUserType, but the result is still the same.
I did not find anyone else having this problem, so I assume the problem is in my code, but I cannot find it.
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();
}
}
}
TimeStamp /, 1899-31-12