StrataFrame Forum

Question on Tutorial

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

By Bo Harris - 2/24/2010

Working through the tutorial and got the CustomerMaintenance form up and running. However when I click on "New" an InvalidCastException is thrown.



Exception message states "Unable to cast object of type 'System.DBNull' to type 'System.String'." Offending line of code is in the 'get' accessor for the CustomerID field and reads - "[font=Courier New]return (System.String)this.CurrentRow["CustomerID"];[/font]".



I know I can put in some code in the get accessor to check for DbNull but was just wondering if there is a property or something that can be set to true so that the generated code will automatically account for null scenarios.
By Dustin Taylor - 2/25/2010

Have you looked at the NULL Value Option and NULL Replacement Value when you edit a field in the BO Mapper? Both of these typically allow you to account for NULLs however you prefer. You can set it to Use Nullable Generics (where it can), or to replace a NULL with a specific value (i.e. "" or String.Empty).

There are several options there, so you may want to take a look and see if any of them suit your fancy Smile.

By Dustin Taylor - 2/25/2010

Forgot to mention, both of those are described in the help docs under Application Framework->Business Layer->Business Object Mapper->Customizing a Field if you need specific direction.