Hi,
I am finding the implementation of the mmType.IsEmpty method confusing with respect to numeric values.
The following is snippet of code taken from the Jump Start example built on the Northwind database:
public string ValidateDiscount(Single discount)
{
string Msg = null;
if (mmType.IsEmpty(discount))
{
this.EntityPropertyDisplayName = "Discount";
Msg = this.RequiredFieldMessagePrefix +
this.EntityPropertyDisplayName +
this.RequiredFieldMessageSuffix;
AddErrorProviderBrokenRule("Discount", Msg);
}
return Msg;
}
This code was created by the BLG and is a rule to enforce the "required" status of the Discount field in the OrderDetails table.
The problem (as I see it) is that mmType.IsEmpty(float value) return true if the float value is zero. For numeric types, I would expect mmType.IsEmpty to return true only if passed a null value.
Through a little poking around, I figured out that by changing the code to
public string ValidateDiscount(Single discount)
{
string Msg = null;
if (mmType.IsEmpty(discount,true))
{
...
the rule will now validate when the value of discount is zero.
Is this behaviour intentional? Is there some way to handle this in the BLG that I am missing?
Throught this process I now understand why I was having problems with required identity field validation on new records. By default the identity field on a new record is set to zero. I would have to reset it to 1 prior to save to avoid violating the business object rule created by the BLG. Not a big deal but a pain.
Best regards,
Tim Holgerson