0

I have a partial class with validation attributes -

[MetadataTypeAttribute(typeof(tblPersonMetadata))]
public partial class tblPerson
{
}

public class tblPersonMetadata
{
   [MaxLength(80)]
   public string PER_MiddleName { get; set; }

   [Required(ErrorMessage = "Enter your Gender")]
   public string PER_Gender { get; set; }
}

The tblPerson is an entity in Entity Framework used in multiple locations. In some locations, I want to leave PER_MiddleName and PER_Gender empty.

How can I selectively disable the validation when tblPerson is used in some objects?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Don
  • 1,532
  • 4
  • 24
  • 47
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Jan 11 '15 at 21:26

1 Answers1

1

My problem is that I need an attribute library to handle [RequiredIf()]. I got a good one - https://github.com/JaroslawWaliszko/ExpressiveAnnotations. It works to my satisfaction.

Don
  • 1,532
  • 4
  • 24
  • 47