Kaush Shetty - 485 - Feb 17, 2014

Hi,

I seem to be facing this issue where, when I get a record from the database using ormlite (screenshots attached below), the date value is defaulting to 1/01/01, whereas the actual date value in the record is: 2014-02-11 00:00:00.000

Any advise as to where I could be going wrong on this one?

Thanks!

Did you insert the Date using OrmLite?

Kaush Shetty:

Nope, it is was inserted manually…

Then I can only assume its related to the timezone of the db. What does the value look like in the DB when you try to insert it using OrmLite?

Kaush Shetty:

I inserted a record using the stand alone unit test and the value in db looks like:
2014-02-18 02:20:21.897

Is that the value you inserted?

Kaush Shetty:

The inserted record’s datetime is read back correctly…

Kaush Shetty:

Yeah, I inserted the value using the DateTime.Now value

ok cool, so not sure what’s up with the manual inserted date, we just return back what the ADO.NET provider gives back

Kaush Shetty:

Am stumped too! Thought it could be something you might have come across…
Will keep trying and let you know what I find…

Kaush Shetty:

Hit the jackpot! :slight_smile:

The integer field in the class were not specified as nullable int!

The values when inserted manually were inserted as NULL in the database. And it barfed with the following exception before it could reach to the part where we assign the values for the date property:

ERROR: System.NullReferenceException: Object reference not set to an instance of an object.
   at lambda_method(Closure , Object , Object )
   at ServiceStack.OrmLite.OrmLiteDialectProviderBase1.SetDbValue(FieldDefiniti<br>on fieldDef, IDataReader dataReader, Int32 colIndex, Object instance)<br>&nbsp; &nbsp;at ServiceStack.OrmLite.OrmLiteWriteExtensions.PopulateWithSqlReader[T](T obj<br>WithProperties, IDataReader dataReader, FieldDefinition[] fieldDefs, Dictionary2 indexCache)

Probably something we could catch in ormlite and set a default value to 0 for integer types?

ok great, just checked in a fix for schema mismatches like this at: https://github.com/ServiceStack/ServiceStack.OrmLite/commit/4eee0f7a177436f873bb568ca1c0905da1d506f2

Now if it’s not nullable, it will set the default value instead.

Kaush Shetty:

Sorry, was AFK, infact SOK (Slept On Keyboard) It was past 3am Melbourne time! :wink:

Awesome! Had a look into the check in.

Just an after thought, should we do the same for other primitive types which are not defined as nullables to have a default value as well?

Thanks a ton!

Kaush Shetty:

Spoke too soon! Noticed it is fixed for all types! Thanks! :slight_smile:

yep all value types are supported :slight_smile: