How to make composite unique key in ASP.NET Boilerplate?

前端 未结 2 1660
时光取名叫无心
时光取名叫无心 2021-01-23 18:22

I have a table which has the Id as primary key, I want to have a composite unique key on Code and Value column. I\'m trying in this way.



        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-23 18:58

    Try this:

    public class SomeClass : Entity
    {
        [Column("Code")]
        public override int Id {get; set;}
    
        public virtual string Name { get; set; }    
    }
    

    [DatabaseGenerated(DatabaseGeneratedOption.None)] will make the Database to NOT create the Code column. What you need in reality is to override the Id and rename it to Code.

    And to have a composite key, simply add

    [Key]
    public virtual int Value { get; set; }
    

    field.

提交回复
热议问题