Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Architecture> auto-mapping of an entity date field from MINDATE to null
 

Pages: 1
Architecture
auto-mapping of an entity date field from MINDATE to null
Page:1/1 

  Print all messages in this thread  
Poster Message
greenstone
User



Location:
Alexandria, VA, USA
Joined on:
20-Jun-2007 03:39:56
Posted:
117 posts
# Posted on: 15-Nov-2011 20:50:30.  
Hi,

Our code uses MINDATE as a standard "null" date, but we need to represent this in the database as database null (main reason is that SQL Server doesn't support date 01-01-0001).

Is there a way to have an entity field always do this mapping (from MINDATE to null and null to MINDATE) for us?

Thanks!
Andy  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
13740 posts
# Posted on: 16-Nov-2011 09:13:51.  
Why are you using MINDATE instead of a nullable dateTime?

  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
34808 posts
# Posted on: 16-Nov-2011 14:44:47.  
You could use a default constraint in the table (so you can save a null and it will be set to the default 'magic' null date). However magic values are not recommended, use a null value instead.
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
greenstone
User



Location:
Alexandria, VA, USA
Joined on:
20-Jun-2007 03:39:56
Posted:
117 posts
# Posted on: 16-Nov-2011 17:57:06.  
You're right, it would be best to avoid the "magic". The reason we didn't use the nullable date type is that an .xsd is the root definition of our data structure for inport/export from the program. Then we xsd.exe code gen a structure of classes (from this .xsd) to represent this data, deserialize xml into these classes, and finally map this data to the data-layer to be sent to the database.

I just checked, and I believe we should be able to set the "isnillable" on the .xsd elements to have xsd.exe generate them as nullable time. But I'm going to need to look at how an "isnillable" xsd.exe generated nullable type is serialized/deserialized from the xml.

I did find a posting on stackoverflow.com about the "nillable", but sounds like an issue with getting the nullable type to serialized/deserialize as one would hope:
--------
I believe if you add nillable="true" in your XML schema definition, XSD will create a nullable type for that element. This is probably a good idea anyway, since you are implying that this value is indeed nillable and this would make your schema definition more explicit in that regard.

Unfortunately, it still includes the corresponding "Specified" field in this case. If you want the serializer to obey the nullable value directly, you will need to manually remove the "xxSpecified" column from the generated code.
---------




Andy  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
7642 posts
# Posted on: 18-Nov-2011 05:03:56.  
I'm sure that there should be a workaround for your xsd/isnullable situation out there. We can't help you with that though.

Another thing you could do is use a TypeConverter that converts from/to a null datetime in DB from/to a MinValue. There are plenty of information about TypeConverters in this forum and also you could grab the sourcecode of the built-in ones from the LLBLGen customer area.
David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.