EF Code First Foreign key must be mapped to some AssociationSet or EntitySets participating in a foreign key association on the conceptual side

c# code-first ef-code-first entity-framework entity-framework-6

Popular Answer

Attempt to manually change the modelbuilder's FK properties' order so that:

modelBuilder.Entity<tblRechnungPosition>()
.HasMany(e => e.tblAngebReches)
.WithRequired(e => e.tblRechnungPosition)
.HasForeignKey(e => new { e.RechNr, e.RechPosNr, e.CompanyID });

I reported a bug to the codeplex EF 6.x Team. Here is a link to it: https://entityframework.codeplex.com/workitem/2947

in the event that doesn't. In the class tblRechnungPosition, try changing the Order Number of the Column Attribute to:

[Key]
[Column(Order = 0)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int RechNr { get; set; }

[Key]
[Column(Order = 2)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int CompanyID { get; set; }

[Key]
[Column(Order = 1)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int PosNr { get; set; }

Note: Composite foreign keys are yours. The order of the properties inside the two different table classes must match.[Columns(Order = <order number>)] .

0
7/27/2016 12:37:00 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow