Null-value mishandled in BOM-generated code


Author
Message
Kirk M Sherhart
Kirk M Sherhart
StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)
Group: Forum Members
Posts: 41, Visits: 259
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"?
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.
Kirk M Sherhart
Kirk M Sherhart
StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)
Group: Forum Members
Posts: 41, Visits: 259
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.
Attachments
NullTest.zip (100 views, 119.00 KB)
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search