user9124444
user9124444

Reputation:

NHibernate: storing / retrieving dates in / from Sqlite

I have this simple object

public class SomeObject
{
    public virtual DateTime TimeStamp { get; }
}

I would like to know how to map a DateTime property sqlite using nhibernate,

Tried something like this

 mapping.Map(Reveal.Member<Something>("TimeStamp"))
            .Default(DateTime.UtcNow.Second.ToString())
            .Generated.Insert()
            .Not.Nullable();

When trying to do an insert

            session.Save(new SomeObject());
            tran.Commit();

I get this

Input string '29' was not in the correct format.' InvalidCastException: Invalid cast from 'Int32' to 'DateTime'.

Upvotes: 0

Views: 79

Answers (1)

Gianmarco Varriale
Gianmarco Varriale

Reputation: 163

mapping.Map(Reveal.Member<Something>("TimeStamp"))
            .CustomType<DateTime>()
            .CustomSqlType("datetime")
            .Default(DateTime.UtcNow.Second.ToString())
            .Generated.Insert()
            .Not.Nullable();

Upvotes: 1

Related Questions