New entity and NOT nullable fields

Posts   
 
    
Andrius
User
Posts: 68
Joined: 04-Apr-2005
# Posted on: 01-Feb-2006 12:41:27   

It is more like a feature request

I really like the idea of LLBL to return type default value for null values in DB In fact I'm so used to it that sometimes I forgot to add default value to NOT NULLable fields which results in runtime SQL exception when trying to insert them in DB.

So my suggestion:

when creating a new enttity set type default value to all NOT NULLable fields in that entity which have no default value constraint attached to it

This helps not to break code with runtime exceptions when DB schema is changing from NULLable to NOT NULLable

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 01-Feb-2006 16:00:08   

This might break your the logic and other things too.

For example an int field is a FK it doesn't allow NULL, do you want LLBLGen Pro automatically to set 0 in that field if no data was inserted by the user!!!

This would break on the database level (refrential integrity).

Also a non-Nullable field is used to force the user to enter a value. If you don't use a default value, then you really want the user to enter a value by his own.

I think we should not work-around this logical validation algorithm.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 02-Feb-2006 11:51:21   

In v2, all value typed fields will be of type Nullable<T>, where T is the value type of the field. All fields by default won't get a default value anymore, so CurrentValue is always null/Nothing.

Reading a field's value, like: myCustomer.CompanyName, and companyName isn't initialized or is NULL in the db, will return the default value for the type of CompanyName, in this case string.Empty. If the field is a value type and nullable, null/Nothing will be returned, otherwise the default value.

This is a breaking change, but more suitable to the way nullable types work.

Frans Bouma | Lead developer LLBLGen Pro