Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get objects not currently in a mapping table using fluent linq
    primarykey
    data
    text
    <p>I'm trying to get all the <code>Catalog</code> objects that currently aren't mapped to a cart using fluent linq. The mapping table <code>cart_catalog_mapping</code> is generated by EF. I use the following domain objects.</p> <p>Cart (removed comments and extra fields that aren't pertinent to the question</p> <pre><code>public partial class Cart : BaseEntity, ILocalizedEntity { public virtual string Name { get; set; } public virtual DateTime OpeningDateUtc { get; set; } public virtual DateTime ClosingDateUtc { get; set; } public virtual bool IsReadonly { get; set; } public virtual bool IsPreviewMode { get; set; } public virtual CustomerRole CustomerType { get; set; } public virtual ICollection&lt;Catalog&gt; Catalogs { get; set; } } </code></pre> <p>Catalog (again removed comments and extra fields that aren't pertinent to the question)</p> <pre><code>public partial class Catalog : BaseEntity, ILocalizedEntity { public virtual string Name { get; set; } public virtual string Code { get; set; } public virtual bool Published { get; set; } public virtual int DisplayOrder { get; set; } } </code></pre> <p>EF5 w/ code first creates the Cart and Catalog table. It also recognizes that the Cart has the list and creates a cart_catalog_mapping table. I'm trying to get all the rows in the <code>Catalog</code> table that don't have a reference in the <code>cart_catalog_mapping</code> table. The SQL I'm envisioning is</p> <pre><code>SELECT * FROM Catalog WHERE Catalog.Id NOT IN (SELECT Catalog_Id FROM cart_catalog_mapping) </code></pre> <p>The fluent linq I've tried to use to get these is the following: public IList GetAllUnassociatedCatalogs() { IRepository _catalogRepository; IRepository _cartRepository;</p> <pre><code> var query = from catalog in _catalogRepository.Table from cart in _cartRepository.Table where !cart.Catalogs.Contains(catalog) select catalog; return query.ToList(); </code></pre> <p>}</p> <p>Unfortunately the returned IList has no elements. (There are currently no rows in the cart or cart_catalog_mapping tables and 3 rows in the catalog table)</p> <p>Almost forgot, the mapping tables</p> <pre><code>public partial class CartMap : EntityTypeConfiguration&lt;Cart&gt; { public CartMap() { this.ToTable("Cart"); this.HasKey(c =&gt; c.Id); this.Property(c =&gt; c.Name).IsRequired().HasMaxLength(100); this.Property(c =&gt; c.IsOnline).IsRequired(); this.HasMany(c =&gt; c.Catalogs) .WithMany() .Map(m =&gt; m.ToTable("Cart_Catalog_Mapping")); } } public partial class CatalogMap : EntityTypeConfiguration&lt;Catalog&gt; { public CatalogMap() { this.ToTable("Catalog"); this.HasKey(c =&gt; c.Id); this.Property(c =&gt; c.Name).IsRequired().HasMaxLength(100); } } </code></pre>
    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.
 

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