Hi
I have a class which containts properties that represent foreign keys within database. These fields are all integers but they are all mandatory fields and the class should force the user to specify/select values for each of these fields. StringRequired doesnt seem to be providing the correct messaging when fields are mandatory.
What would be the best way/workaround to handle a case where a non-string value is required. I would prefer not to extend the CSLA if possible
Thanks
Why not use
ValidationRules.AddRule( _
AddressOf Validation.CommonRules.IntegerMinValue, _ New Validation.CommonRules.IntegerMinValueRuleArgs("PropertyName", 1))Adding FriendlyName argument if required. Your FK probably all default to zero. If you don't like default message you can use something like
ValidationRules.AddRule(
AddressOf ValidateTownID(Of <YourObject>), "TownID")and implement the Rule as below:
Private
Shared Function ValidateTownID(Of T As <YoutObject>)(ByVal target As Object, ByVal e As Validation.RuleArgs) As Boolean If target.TownID = 0 Thene.Description = "Please choose a Town"
Return False End If Return True End FunctionCopyright (c) Marimer LLC