Setting an entities property value to be null

Posts   
 
    
Posts: 254
Joined: 16-Nov-2006
# Posted on: 17-Apr-2007 21:09:17   

Just reviewing this section in the documentation

How do I insert a NULL value for a field in an existing entity? Because a save action of an existing entity will update the changed fields only, we can't use the mechanism used with saving a new entity. Instead we have to change the value of the field we want to set to NULL to a value, so it is changed, and at the same time the value should then be used to set the field to NULL. Because the properties reflecting the fields are typed, some with value types, we can't set the value typed properties to null/Nothing. Instead we use a method to do that.

Selfservicing / Adapter // C# CustomerEntity customer = new CustomerEntity("CHOPS"); customer.SetNewFieldValue((int)CustomerFieldIndex.ContactTitle, null); // now save the customer. ContactTitle will become NULL.

I don't understand the point

Because the properties reflecting the fields are typed, some with value types, we can't set the value typed properties to null/Nothing

As .NET 2.0 support nullable types, why can't a null value be specified for a property?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39922
Joined: 17-Aug-2003
# Posted on: 17-Apr-2007 22:27:20   

Not always fields are generated as nullable types for example because the user doesn't want to use the field as a nullable type (migrating code from .net 1.x to 2.0 for example). Sure, if hte field is a nullable type, you could set it to null as well. simple_smile

Frans Bouma | Lead developer LLBLGen Pro