Entity Framework Code First Using One column as Primary Key and another as Auto Increment Column

前端 未结 4 1912
挽巷
挽巷 2020-12-09 15:08

I have a class named Sale

public class Sale
{
    public int Id { get; set; }
    public string TrNo { get; set; }
    public DateTime Date          


        
4条回答
  •  醉酒成梦
    2020-12-09 16:07

    You can also do this with Data Annotations:

    public class Sale
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
    
        [Key]
        public string TrNo { get; set; }
    
        public DateTime Date { get; set; }
        public int CustomerID { get; set; }
    
        public ObservableCollection SaleDetails { get; set; }
    }
    

提交回复
热议问题