Generate as Nullable Type (2.0+) in ver 2.5 Designer

Posts   
 
    
GizmoTN76
User
Posts: 36
Joined: 22-Oct-2007
# Posted on: 06-Feb-2008 01:28:22   

I'm sure there's a setting somewhere that I can specify this but I've been pulling my hair out to find it and could use a hint as to where to look in the designer.

Right now the default behavior for class generation is to make nullable value type columns in the database nullable, and non nullable ones non nullable. Unfortunately when this happens it supplies the default values for these nonnullable ones (for instance 0 for an integer.) What I would prefer to have is all of them be nullable and then use the validation logic check to see if the user specified a value (ie pop an error provider for required fields.) It looks like the designer supports this with the (.NET 2.0+) Generate as nullable type option on the columns however this option is grayed out in the designer for the columns in my entities.

Is there a way for me to switch this on globally to automatically make everything nullable to allow for my use case? Essentially I want to let a null pass through the property to the validation (right now it just defaults it back to the default empty value and I don't have a hook to know that the value really is empty.)

I have looked for a global place other than the generation code to set framework version etc. and can't seem to locate it to turn this functionality on. The designer version I'm using shows a version number of 2.5.0.0, since this isn't really a runtime thing I don't imagine that helps.

I guess the second question would be if there is indeed a way to turn this on, what the best methodology to update every column in my project to reflect this nullable state, and how to set it for all new entities.

I'm sure I'm missing something silly here but I figured I'd throw it to the experts simple_smile .

Thanks in advance,

Scott

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 06-Feb-2008 11:01:06   

Well there is no simple selectable option to create nullable types for non-nullable database fields.

You may use TypeConverters, to convert from normal .NET value types to nullable Types.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 06-Feb-2008 13:59:39   

This is grayed out at the moment because the target field isn't nullable. This could lead to problems when saving entities and therefore it's not possible to make these fields nullable.

You don't need to have the fields to be nullable to check if the user has set a value. Every entity has methods to test for that: TestCurrentFieldValueForNull and TestOriginalFieldValueForNull.

The first one is for testing if the user has set the field to NULL, and the second one is for testing if the field was null in the db (so doesn't apply for new entities).

If you want to test if a field is set, check its Changed flag.

I'd stay away from Nullable<T> if possible, not all .NET framework elements work OK with these types (read: winforms)

Frans Bouma | Lead developer LLBLGen Pro