Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MmType.IsEmpty confusing
Message
De
08/08/2008 13:24:21
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
MmType.IsEmpty confusing
Divers
Thread ID:
01337590
Message ID:
01337590
Vues:
44
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:
	         /// <summary>
		/// Validates the Discount
		/// </summary>
		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
/// <summary>
		/// Validates the Discount
		/// </summary>
		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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform