0

I have got table connecting other tables. Entity Framework wants a primary key. I'd like this table have only ID from other tables without additional primary key. What should I do to fix this error?

Katniss
  • 7
  • 4

2 Answers2

0

You can create a primary composite key

public class YourEntity
{
 [Column(Order = 0), Key, ForeignKey("FieldFromAnotherTable_1")]
 public int FieldFromAnotherTable_1_ID { get; set; }

 [Column(Order = 1), Key, ForeignKey("FieldFromAnotherTable_2")]
 public int FieldFromAnotherTable_2_ID { get; set; }

 public virtual Type1 FieldFromAnotherTable_1{ get; set; }
 public virtual Type2 FieldFromAnotherTable_2{ get; set; }

}
The One
  • 4,560
  • 5
  • 36
  • 52
0

You can mark those ID`s from other tables with a Key attribute. EF would see this and make a primary key from those columns.

Also, you can read this article Creating Composite Key Entity Framework

Community
  • 1
  • 1
Roman Hapatyn
  • 19
  • 1
  • 5