How can I add my attributes to Code-Generated Linq2Sql classes properties?

前端 未结 6 831
甜味超标
甜味超标 2020-12-01 10:49

I would like to add attributes to Linq 2 Sql classes properties. Such as this Column is browsable in the UI or ReadOnly in the UI and so far.

I\'ve thought about usi

6条回答
  •  心在旅途
    2020-12-01 11:25

    You can use a partial class to make your entity implement a interface that declares the same properties of your entity and then put the attributes on the interface.

    This way you can use the interface type to get the attributes from the properties.

    I don't know if you will be able to use the attributes this way, but you can try something like that.

    Example:

    
    public interface IConcept {
        long Code { get; set; }
        [Unique]
        string Name { get; set; }
        bool IsDefault { get; set; }
    }
    
    public partial class Concept : IConcept { }
    
    [Table(Name="dbo.Concepts")]
    public partial class Concept
    {
    //...
    }
    

提交回复
热议问题