Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I figured it out. There was a logical disconnect between by database structure and my Entity model.</p> <p>The productImages table supports a *-1 mapping therefore the Products POCO class needs to have a collection of ProductImages. Then the entities need to be configured as follows:</p> <pre><code>public class ProductImagesMap : EntityTypeConfiguration&lt;ProductImage&gt; { //Other field and key configuration... this.HasRequired(t=&gt;t.Image).WithRequiredDependent(); this.HasRequired(t =&gt; t.Product) .WithMany(t =&gt; t.ProductImage) .HasForeignKey(d =&gt; d.SKU); } public class ProductImage { public int ImageId { get; set; } public string SKU{ get; set; } public virtual Image Image { get; set; } public virtual Product Product { get; set; } } public class Product { public Product() { this.Features = new List&lt;Feature&gt;(); } public int ProductId { get; set; } public string Name { get; set; } public string SKU{ get; set; } public virtual Brand Brand { get; set; } public virtual ICollection&lt;ProductImage&gt; ProductImages { get; set; } } </code></pre> <p>I struggled with trying to configure this relationship in the ProductMap class (as Products in the parent/mater table), it was not until configured it from the ProductImages class that it worked so my two open questions are: </p> <p>1) What rules determine which entity drives the relationship configuration?</p> <p>2) Is there a way I can configure the Products POCO class to have an ICollection Images property and bypass the ProductImage entity all-together as ProductImage only serves as a link table between products and images?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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