Monday 24 August 2015

.Net Data Annotations : Add composite Primary Key Code First

Following is the way we can add composite primary key for an entity using Data Annotations.

    
        [Key, Column(Order = 0)]
        [Display(Name = "Year")]
        [Range(2015, 2050)]
        public int Year { get; set; }

        [Key, Column(Order = 1)]
        [Range(1, 12)]
        [Display(Name = "Month")]
        public int Month { get; set; } 


No comments:

Post a Comment