Note that there are some explanatory texts on larger screens.

plurals
  1. POFluentValidation Call RuleSet and Common Rules
    primarykey
    data
    text
    <p>I have the following class </p> <pre><code>public class ValidProjectHeader : AbstractValidator&lt;Projects.ProjectHeader&gt; { public ValidProjectHeader() { RuleFor(x =&gt; x.LobId).Must(ValidateLOBIDExists); RuleFor(x =&gt; x.CreatedByUserId).NotEmpty(); RuleFor(x =&gt; x.ProjectManagerId).NotEmpty(); RuleFor(x =&gt; x.ProjectName).NotEmpty(); RuleFor(x =&gt; x.SalesRepId).NotEmpty(); RuleFor(x =&gt; x.DeliveryDate).NotEmpty(); RuleFor(x =&gt; x.ProjectStatusId).NotEmpty(); RuleFor(x =&gt; x.DeptartmentId).NotEmpty(); RuleFor(x =&gt; x.CustomerId).NotEmpty(); RuleSet("Insert", () =&gt; { RuleFor(x =&gt; x.ProjectLines).Must(ValidateProjectLines).SetCollectionValidator(new ValidProjectLine()); }); RuleSet("Update", () =&gt; { RuleFor(x =&gt; x.ProjectLines).SetCollectionValidator(new ValidProjectLine()); }); } </code></pre> <p>and what i am trying to do is call the validation with the rulset but i also want to return the "common" rules when i call the validation with the RuleSet.</p> <p>the Code I have for calling the validation is as follows</p> <pre><code>public abstract class BaseValidator { private List&lt;ValidationFailure&gt; _errors; public bool IsValid { get; protected set; } public List&lt;ValidationFailure&gt; Errors { get { return _errors; } protected set { _errors = value; } } public virtual bool CallValidation() { Errors = new List&lt;ValidationFailure&gt;(); ValidatorAttribute val = this.GetType().GetCustomAttributes(typeof(ValidatorAttribute), true)[0] as ValidatorAttribute; IValidator validator = Activator.CreateInstance(val.ValidatorType) as IValidator; FluentValidation.Results.ValidationResult result = validator.Validate(this); IsValid = result.IsValid; Errors = result.Errors.ToList(); return result.IsValid; } public virtual bool CallValidation(string ruleSet) { Errors = new List&lt;ValidationFailure&gt;(); ValidatorAttribute val = this.GetType().GetCustomAttributes(typeof(ValidatorAttribute), true)[0] as ValidatorAttribute; IValidator validator = Activator.CreateInstance(val.ValidatorType) as IValidator; FluentValidation.Results.ValidationResult result = validator.Validate(new FluentValidation.ValidationContext(this, new PropertyChain(), new RulesetValidatorSelector(ruleSet))); IsValid = result.IsValid; Errors = result.Errors.ToList(); return result.IsValid; } public BaseValidator() { Errors = new List&lt;ValidationFailure&gt;(); } } </code></pre> <p>I can call the Method <code>CallValidation</code> with the member <code>ruleSet</code> but it is not calling the "common" rules also. </p> <p>I know I can create a "Common" RuleSet for running these rules but in that case i would have to call the validation with the Common RuleSet always.</p> <p>Is there any way I can call the RuleSet and also call the common rules.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload