Note that there are some explanatory texts on larger screens.

plurals
  1. POEF 4.1 Fluent API. How to map two entities while using an existing join table which has three id columns?
    primarykey
    data
    text
    <p>I have three entities (EntityA, EntityB, EntityC) in code and their respective tables (TableA, TableB, TableC) in the database. I also have an existing join table that has three ID columns(TableA_ID, TableB_ID, TableC_ID).</p> <p>In code, the entities are related as follows:</p> <pre><code>MODELS: public class EntityA { public Guid EntityA_ID { get; set } ..... // Each EntityA can be associated with 0 or Many EntityB public virtual ICollection&lt;EntityB&gt; EntityBCollection { get; set; } } public class EntityB { public Guid EntityB_ID { get; set; } ..... // Each EntityB can be associated with 0 or Many EntityA public virtual ICollection&lt;EntityA&gt; EntityACollection { get; set; } // Each EntityB can be assocated with 0 or Many EntityC, // but it becomes 0 or 1 when EntityB is associated with an EntityA public virtual EntityC EntityC { get; set; } } public class EntityC { public Guid EntityC_ID { get; set; } ...... // Each EntityC an only be associated with a EntityB // an EntityC does not exist on its own public virtual EntityB EntityB { get; set; } } DATA CONTEXT: modelBuilder.Entity&lt;EntityB&gt;() .HasOptional(entityb =&gt; entityb.EntityC) .WithRequired(entityc =&gt; entityc.EntityB) .Map(map =&gt; { map.ToTable("ThreeIDColumnJoinTable").MapKey(new string[]{"EntityA_ID", "EntityB_ID", "EntityC_ID"}); }); </code></pre> <p>I keep on getting the following error:</p> <pre><code>Unable to determine the principal end of an association between the types 'EntityC' and 'EntityB'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations. </code></pre> <p>Any ideas on how I can reconfigure the mapping in the DATA CONTEXT so it will not produce an error and it will also include the relationship of EntityA that is specified in the ThreeIDColumnJoinTable?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload