StrataFrame Forum

BO Mapper - Custom Field Properties (NULL Value Option)

http://forum.strataframe.net/Topic8468.aspx

By Tim Dol - 4/24/2007

In 1.6 I noticed two new 'NULL Value Options' in customer field properties (BO Mapper). I don't see these explained in the documentation. Can you explain how to use them?

1) Return Alternate on Null / Set Null on Alternate (reference type)

2) Return Alternate on Null / Set Null on Alternate (value type)

By Peter Jones - 4/24/2007

Hi,

Having just gone down this path I can offer this insight - it enables you to propergate nulls into your database. In my case I have the alternate value of string.empty for nullable string fields. By using these new options if the form control for the column is 'blanked out' then Null is saved to the database rather than "".

Cheers, Peter

By StrataFrame Team - 4/25/2007

Yep, Peter is right.  The "Return Alternate on NULL" option only returned an alternate value if there was a DBNull.Value in the database.  However, if you set the property back to your alternate value, that alternate value was placed in the DataTable (not a DBNull.Value value). 

With the "Return Alternate on Null / Set Null on Alternate" options, it works the same as the above with a Get (the alternate is returned in the case of the DBNull.Value in the DataTable); however, the Set now tests the incoming value and if it equals the alternate value, DBNull.Value is copied into the DataTable.

The difference between the (reference type) and (value type) options really only affects VB.  When you specify the value type option, the = operator is used to compare the alternate value to the incoming value for the Set; with the reference type option, the "Is" operator is used to compare the alternate value to the incoming value.  With C#, both values do the same thing... since the "is" keyword is not a comparison operator like it is in VB; in C#, the "==" operator is used for both.  So, generally, you're going to want to use the (value type) option.  Only in a few cases in VB are you actually going to want to use the "Is" operator to compare your alternate to the value.

By choyt - 8/9/2007

Ok...time for a really stupid question...(and boy do I feel stupid asking this)...but which datatypes are value and which are reference? I understand that only Value types can be null so I'm guessing that a Date is a reference and an Int32 would be value?

Thanks!

By Peter Denton - 8/9/2007

G'day

Value Types are those that derive from the ValueType Class, and are allocated on the Stack and therefore are deallocated as soon as they go out of scope. They include Boolean, Byte, Char, Decimal, Single, Double, all the integer types, DateTime, Guid, Timespan.

Reference Types are allocated on the heap and are cleaned up by garbage collection. They include String, Array etc.

Hope this helps

Peter

By choyt - 8/10/2007

Thanks Peter...that does indeed help!
By StrataFrame Team - 8/10/2007

Yep, Peter is right.  Any structure is a value type, and by definition, always has a value (you will never get a NullReferenceException by referencing a value type variable in code...).  Reference types are classes, and the variable only stores a reference to the object, not the actual object, so the reference can be a null pointer (allowing you to get a NullReferenceException).  So, Peter is right: simple types are all value types, while classes are all reference types.  You can always tell by opening the Object Browser in VS (View -> Object Browser) and looking at the icon next to the type.

You will notice that the symbol next to the IntXX types indicates a simple type, which is always a value type.  Also, the symbol next to IntPtr is thicker, which represents a structure, which is also a value type.  The thinner symbol next to the exception types indicates that the types are classes, which are reference types.

You'll also notice that when you expand the plus sign beside the value types, they all inherit from System.ValueType.  You cannot directly inherit from ValueType (I don't think...), but the compiler automatically does this when you define something as a structure (the same way a class you define automatically inherits from System.Object).

Hope that helps explain things some more Smile