StrataFrame Forum

Null-value mishandled in BOM-generated code

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

By Kirk M Sherhart - 4/3/2009

I have a simple table with a nullable numeric field JOB_TYPE, which BOM sees as a System.Decimal value. If I set BOM to use "Nullable Generics" AND to create property accessing event for the field, I get the following BOM-generated code for the field accessor

        public Nullable<System.Decimal> JOB_TYPE

{

get

{

object loValue;

PeopleBOFieldAccessingEventArgs e;

Nullable<System.Decimal> loReturn;

loValue = this.CurrentRow["JOB_TYPE"];

if (loValue == DBNull.Value)

{

loReturn = (Nullable<System.Decimal> )null;

}

else

{

loReturn = new Nullable<System.Decimal> ((System.Decimal)loValue);

}

e = new PeopleBOFieldAccessingEventArgs(PeopleBOFieldNames.JOB_TYPE, loReturn);

this.OnFieldPropertyAccessing(this, e);

return new Nullable<System.Decimal> ((System.Decimal)(e.ValueToReturn)); <===BOOM!

}

set

{...}



If JOB_TYPE is null, loReturn becomes a null of type decimal?, but is cast (boxed) into a null of type object for the eventargs. After the event is processed (there is no code in the event itself), the value of e.ValueToReturn is a null of type object, which causes the exception when attempting the cast to System.Decimal.



If this a "bug" or "feature"?
By Trent L. Taylor - 4/4/2009

Please send me a sample.  Not able to reproduce in the same fashion.  A workaround in any case is to get this the way that you like then go back into the BO mapper and use a Custom Code option.  Paste the adjusted code into the Customer Code section so that when the BO is rebuilt through the mapper your changes don't get overwritten.  But I would still like to see a sample when possible.
By Kirk M Sherhart - 4/6/2009

Hi Trent



I've attached some code/text that illustrates the problem. I created a simple, 2-field table with a single record of value (1, null). I generated the BO (see included BOM properties screenshot, etc.) I've included the BOM-generated code for the object. I created a simple form with a button that executes the included code (a simple retrieval and access of the nullable field value.) Clicking the button causes the BOM-generated code for the NULL_TEST_VALUE field accessor to throw a NullReferenceException.



Hope this helps you to track down the problem.
By Trent L. Taylor - 4/8/2009

I have not yet had a chance to look at this...sorry for the delay.  I have added it to the list, so we are making progress! Smile

The last two weeks have been crazy busy around here....so sorry for the delay.