Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Required but allow Zero
Message
From
19/10/2010 08:40:17
 
 
To
18/10/2010 16:57:14
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01485947
Message ID:
01486100
Views:
43
>>>>Hi,
>>>>
>>>>I've used the Business Layer Generator and it has generated a rule like this for a field:
>>>>
>>>>
		/// <summary>
>>>>		/// Validates the Min Age
>>>>		/// </summary>
>>>>		public string ValidateMinAge(byte minAge)
>>>>		{
>>>>			string Msg = null;
>>>>			if (mmType.IsEmpty(minAge))
>>>>			{
>>>>				this.EntityPropertyDisplayName = "Minimum Age";
>>>>
>>>>				Msg = this.RequiredFieldMessagePrefix + 
>>>>					this.EntityPropertyDisplayName + 
>>>>					this.RequiredFieldMessageSuffix;
>>>>
>>>>				AddErrorProviderBrokenRule("MinAge",  Msg);
>>>>			}
>>>>			return Msg;
>>>>		}
>>>>
>>>>This causes a zero value to be invalid. What do I do to disallow null values but allow a zero value?
>>>
>>>Frank, that method gets the proposed value passed in and checks if it is empty. You can modify this method anyway you want to check it and set the return message for a broken rule the way you want also. Why is age a byte type?
>>>Tim
>>
>>
>>Thanks Tim,
>>
>>as this is generated code I don't want to modify it. Is there some setting in the business layer generator that I need to change?
>>
>>Also, how come 0 is considered empty? Shouldn't there be something to check if it is not null, rather than empty if 0 is considered empty?
>>
>>To answer your question about age being a byte type, I have no idea, in my database it is a tinyint, so I guess MM.NET uses bytes to represent that?
>
>
>Frank, it is generated in the business layer because you checked the "required" on the field. You are free to modify that method as you see fit and that should not be a problem. If you want to move it to your partial class then it wouldn't be overwritten if you re-run the generator. (something I very rarely do).

Yes, Tim, I understand that, it was actually checked automatically by the generator since the field does not allow nulls, but why is 0 not considered a valid value? I thought required was a check for NOT NULL.

Does the conversion from tinyint to byte sound correct to you?

I am afraid that I regularly rerun the generator and like the use of the partial classes. I'm just not comfortable adding in a new field to a table and then manually adjusting the code in the BO to handle it. The couple times I tried it I missed something and messed things up pretty spectacularly.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform