Note that there are some explanatory texts on larger screens.

plurals
  1. POAttributes of properties in MetadataType are ignored by EntLib Validation
    primarykey
    data
    text
    <p>It's an EntLib-Validator-issue again. I'm playing with EntLib 5.0 in C# and .Net 4.0 on XP pro.</p> <p>I have some business objects (partial classes) generated by T4 templates. So I decided to put their validation attributes in buddy-classes by using <code>MetadataTypeAttribute</code> as definitely recommended by the documentation of entLib 5.0 (<a href="http://msdn.microsoft.com/en-us/library/ff664465%28PandP.50%29.aspx" rel="nofollow">msdn</a>). But the <code>Validator</code> object I get from the ValidatorFactory doesn't know about the validation attributes, defined in the metadata-class.</p> <p>The business object is defined like this:</p> <pre><code>[MetadataType(typeof(PatientMetadata))] public partial class Patient { private string _Name; private int _DiagnosisCount; public int DiagnosisCount { get { return _DiagnosisCount; } set { if (value != _DiagnosisCount) { _DiagnosisCount = value; } } } public string Name { get { return _Name; } set { if (value != _Name) { _Name = value; } } } } </code></pre> <p>And the metadata class like this, according to documentation:</p> <pre><code>public class PatientMetadata { [RangeValidator(4)] public int DiagnosisCount { get; set; } [StringLengthValidator(64, ErrorMessage = "Name must not exceed 64 chars.")] public string Name { get; set; } } </code></pre> <p>If I know try to do validation this way:</p> <pre><code> var factory = ValidationFactory.DefaultCompositeValidatorFactory; var validator = factory.CreateValidator&lt;Patient&gt;(); </code></pre> <p>...then watching into <code>validator</code> (during debugging) already says, that it's just an <code>AndCompositeValidator</code> without any children validators. Again, if I put the validation attributes right in the <code>Patient</code> class, it works perfectly.</p> <p>By now, I have no real idea, what I'm missing here, since I think doing everything according to the docs.</p> <p>Thanks in advance to you guys!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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