In the Entity Framework, I would like to use two foreign keys as the primary key of another type of object.
public class CustomerExtensionValue {
[Key]
[Column(Order = 0)]
public Customer Customer { get; set; }
[Key]
[Column(Order = 1)]
public CustomerExtension Extension { get; set; }
[Required]
public string Value { get; set; }
}
However, this gives me an error that the key will be missing. \tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'CustomerExtensionValue' has no key defined. Define the key for this EntityType.
I know that I could define two more attributes containing primary keys of reference entity types. Is Visual Studio smart enough to use its primary keys on its own?
source
share