Adding custom property attributes in Entity Framework code

前端 未结 6 1731
迷失自我
迷失自我 2020-12-08 14:43

Is there any way to add custom attributes to properties in EF generated code? The only thing I can see as a plausible solution would be to come up with a custom T4 template

6条回答
  •  眼角桃花
    2020-12-08 15:05

    You can create interface and declare attribute on interface.

    partial class Person : IPerson {}
    
    public interface IPerson
    {
        [Required]
        string Name { get; set; }
    }
    

提交回复
热议问题