Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MmType.IsEmpty confusing
Message
De
08/08/2008 16:45:58
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
08/08/2008 13:24:21
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01337590
Message ID:
01337685
Vues:
12
Hi Tim,

>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

In the case of a discount wouldn't you want to be able to set it to 0? I think for this example the idea was they can't leave it empty (null) but if there is no discount then it should be set to zero. mmType.IsEmpty is only making sure the field didn't get left empty. You can handle the validation anyway you want to in your ValidateSomeField methods.

An identity field should not be defaulting to zero after created by the BLG. I have seen some of my int fields marked as required and default of zero, but I always just uncheck the default checkbox on those. For instance I have had foreign key fields that are required, but the BLG had the default checkbox checked by default with zero in the default value. I just uncheck those as that would make no sense. If an identity field is marked in the database as the primary key, it should come up in the BLG with both the required and default checkboxes disabled.
Tim
Timothy Bryan
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform