Fluent NHibernate CheckProperty and Dates
        Posted  
        
            by Chris C
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Chris C
        
        
        
        Published on 2010-02-23T18:34:18Z
        Indexed on 
            2010/06/17
            16:33 UTC
        
        
        Read the original article
        Hit count: 248
        
I setup a NUnit test as such:
new PersistenceSpecification<MyTable>(_session)
    .CheckProperty(c => c.ActionDate, DateTime.Now);
When I run the test via NUnit I get the following error:
SomeNamespace.MapTest: 
System.ApplicationException : Expected '2/23/2010 11:08:38 AM' but got 
'2/23/2010 11:08:38 AM' for Property 'ActionDate'
The ActionDate field is a datetime field in a SQL 2008 database. I use Auto Mapping and declare the ActionDate as a DateTime property in C#.
If I change the test to use DateTime.Today the tests pass.
My question is why is the test failing with DateTime.Now? Is NHibernate losing some precision when saving the date to the database and if so how do prevent the lose? Thank you.
© Stack Overflow or respective owner