Note that there are some explanatory texts on larger screens.

plurals
  1. POFluent NHibernate generating additional join and creating duplicate entities in bi-directional relationship
    primarykey
    data
    text
    <p>a Venue can have one or more Areas and, inversely, each Area has exactly one Venue. I'm using build 1.0.0.636 of Fluent NHibernate.</p> <p>When I added Fetch.Join() to the VenueMap to eliminate lazy loading, the SQL generated includes a join back to the Area table, from itself: (simplified, obviously) </p> <pre><code>SELECT * FROM Areas LEFT OUTER JOIN Venues on Areas.VenueId = Venues.Id LEFT OUTER JOIN Areas as Areas2 on Venues.Id = Areas2.VenueId </code></pre> <p>This causes it to return duplicate rows so each Venue has duplicate Areas in it's collection. I've tried using MoreLinq's DistinctBy after getting all Areas, but this still leaves each Venue having duplicate Areas - it just removes duplicate areas from the main collection. It also feels really filthy as I'm returning about three times as much data and then throwing it away.</p> <p>As I alluded to above, my query is to get all Areas and have all Venues eager loaded.</p> <p>Domain entities: </p> <pre><code>class Venue { int Id; IList Areas; } class Area { int Id; Venue Venue; } </code></pre> <p>Mappings: </p> <pre><code>public class VenueMap : ClassMap&lt;Venue&gt; { public VenueMap() { Table("Venues"); HasMany(v =&gt; v.Areas) .KeyColumn("VenueId") .Inverse() .Fetch.Join(); } public class AreaMap : ClassMap&lt;Area&gt; { public AreaMap() { Table("Areas"); Id(a =&gt; a.Id); References(a =&gt; a.Venue).Column("VenueId").Not.Nullable(); } } </code></pre> <p>Any ideas how I can sort my mappings out and remove the duplicate Areas? I've done sooo much Googling already...</p> <p>Thanks, Monty</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.
 

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