Thursday, May 31, 2012

Make dOOdads understand SQL Datatype Date


For you that are using the  dOOdads .NET architecture and are generating source based on tables that use the datatypes Date or Time and are getting Unknown in your code. Here is a simple solution to make MyGeneration create code that supports SQL data types Date and Time:

Locate your DbTargets.xml and add

<Type From="date" To="SqlDbType.Date" />
<Type From="time" To="SqlDbType.Time" />
 
Locate your Languages.xml and add

<Type From="date" To="DateTime" />
<Type From="time" To="TimeSpan" />
 
The dOOdads allready known the datatype TimeSpan so the rest is handlesd by the framework.
To add a Date in code use DateTime.TimeOfDay to get the TimeSpan

2 comments:

fperugini said...

What about the DateTime datatype? I am having nothing but problems with DateTime and SQLite.

Christian Berg-Henry said...

DateTime works as expected in SQL Server. I have not tried the SQLite DB. But a tip is to use the date parts when comparing. Just comparing datetime values when the date part is what you want will not provide the expected result. When checking dates against dates use the Date part end exclude the time part. The time is seldom equal across one date...