How to add data annotation for entities automatically created by Data-First?

前端 未结 3 1510
-上瘾入骨i
-上瘾入骨i 2020-12-28 23:53

If model-first, we use [MetadataType(typeof(ConceptMetadataSource))] to attach a MetadataSource file which contains all the data annotations like [Hidden

3条回答
  •  死守一世寂寞
    2020-12-29 00:32

    define a view model like

    public class VMConcept
    { 
        public Concept NewConcept {get; set;}
    }
    
    [MetadataType(typeof(ConceptMetadataSource))]
    public partial class Concept{}
    
    public class ConceptMetadataSource {
    
     [Required(ErrorMesssage="This Field is required")]
     public string PropertyName {get; set;}
    }
    

提交回复
热议问题