As promised
http://fabiomaulo.blogspot.com/2010/01/nhibernatevalidator-changing-validation.html

2010/1/15 Fabio Maulo <[email protected]>

> As self-reminder I'll write a post.
> This is a possible solution (and there are some others):
> public class CustomerValidation : ValidationDef<Customer>
>  {
> public CustomerValidation()
> {
>  Define(e => e.CompanyName).NotNullableAndNotEmpty();
> Define(e => e.VatIdentificationNumber).IsPartitaIva();
>  }
> }
>
> public class InvoiceValidation : ValidationDef<Invoice>
>  {
> public InvoiceValidation()
> {
>  ValidateInstance.By((invoice, validationContext) =>
> {
> bool isValid = true;
>  if(string.IsNullOrEmpty(invoice.Customer.VatIdentificationNumber))
> {
>  isValid = false;
> validationContext.AddInvalid<Customer, string>("To be used in an invoice
> the Customer should have the VatNumber",
>                                                p =>
> p.VatIdentificationNumber);
> }
>  return isValid;
> });
> Define(e => e.Amount).Satisfy(amount => amount > 2.0m).WithMessage("The
> amount should be greater than 2€");
>  }
> }
>
> 2010/1/14 Fabio Maulo <[email protected]>
>
> revin... I have re-read your question... perhaps, and I mean perhaps, we
>> can implements a new feature...
>> So far, for a relationship, we are giving only the ability to define a
>> "cascade-validation" using [Valid].
>> We can extend it with:
>> Valid(Type entityValidator) where entityValidator shoud implements
>> IValidator
>> In this way you can define which is the "cascade-validation" to use from
>> the aggregate.
>>
>> The other possible improvement is
>> [Valid(Force = true)]
>> In this way the user can fore the initialization of the
>> relation/association.
>>
>> If you think that it is viable please add an issue, for each improvement,
>> in our issue tracker.
>> Thanks.
>>
>> P.S. a copy of this mail was sent to dev-list
>>
>> 2010/1/13 revin <[email protected]>
>>
>>> Hi,
>>>
>>> I have a structure:
>>>
>>>        [Serializable]
>>>        public struct Address
>>>        {
>>>                private string _street1;
>>>                private string _street2;
>>>                private string _suburb;
>>>                private string _state;
>>>                private string _postcode;
>>>                private string _country;
>>>                :
>>>       }
>>>
>>> Struct Address can be used by Employee or Customer.
>>> However, Address in Employee and Customer may have different
>>> constraints.
>>>
>>> For example:
>>> Employee.Address.County can only be Australia and NewZealand
>>> However, Customer.Address.Country can by anything (NotNull).
>>>
>>> I am using Attribute and Xml file to configure the validation.
>>> Is it possible to achieve?
>>>
>>> Regards,
>>> Revin.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "nhusers" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<nhusers%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/nhusers?hl=en.
>>>
>>>
>>>
>>>
>>
>>
>> --
>> Fabio Maulo
>>
>>
>
>
> --
> Fabio Maulo
>
>


-- 
Fabio Maulo
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Reply via email to