Note that there are some explanatory texts on larger screens.

plurals
  1. PODateTime incorrect when added to SQLite DB through (Fluent)NHibernate
    text
    copied!<p>I have a component that i want to store to an SQLite database.</p> <pre><code>public class Comp : Entity { public virtual DateTime TimeStamp { get; set; } public virtual String Name { get; set; } } public class CompMap : ClassMap&lt;Comp&gt; { public CompMap() { Id(x =&gt; x.Id); Map(x =&gt; x.TimeStamp); Map(x =&gt; x.Name); } } </code></pre> <p>Nothing fancy really.</p> <p>The problem is that the <code>TimeStamp</code> 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 <code>DateTime</code> to the database</p> <pre><code>NHibernate: INSERT INTO "Comp" (TimeStamp, Name) VALUES (@p0, @p1); select last_insert_rowid(); @p0 = 26.02.2010 10:08:09, @p1 = 'test1' </code></pre> <p>To me it looks like the <code>DateTime</code> is in a string format (might just be the <code>.ShowSQL()</code> command though) and SQLite can't handle the format (it's a german datetime formating) I tried to change the format using an <code>IUserType</code> but the result is still the same.</p> <p>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.</p> <p>Here's the testcode i use to initialize the DB and insert the value to the DB</p> <pre><code>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 =&gt; m.FluentMappings.AddFromAssembly(typeof(Comp).Assembly)) .ExposeConfiguration(config =&gt; { 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(); } } } </code></pre> <p>When executing this command and checking the DB Content the TimeStamp doesn't have the current date/time but 1899-31-12</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload