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

前端 未结 6 730
甜味超标
甜味超标 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:22

    You can take advantage of the new Metadata functionality in the System.ComponentModel.DataAnnotations which will allow us to separate the MetaData from the existing domain model.

    For example:

    [MetadataType (typeof (BookingMetadata))]
    public partial class Booking
    {
     // This is your custom partial class     
    }
    
    public class BookingMetadata
    {
     [Required] [StringLength(15)]
     public object ClientName { get; set; }
    
     [Range(1, 20)]
     public object NumberOfGuests { get; set; }
    
     [Required] [DataType(DataType.Date)]
     public object ArrivalDate { get; set; }
    }
    

提交回复
热议问题