Composite Key with EF 4.1 Code First

前端 未结 2 1427
独厮守ぢ
独厮守ぢ 2020-11-29 19:50

I am trying to figure out how to have a composite key using EF code First 4.1 RC.

Currently, I am using the [Key] Data Annotation, but I am unable to specify more th

2条回答
  •  北海茫月
    2020-11-29 20:07

    We don't use the annotations, instead we override the model builder, in which case you can do something like:

    modelBuilder.Entity().HasKey(a => new { a.ActivityId, a.ActivityName });
    

提交回复
热议问题