Hi all,

I apologize for cross posting this message to the dev list, but I
haven't gotten a response on the users list yet.  Hopefully someone
here can shed some light on the behavior I'm seeing.

I have a bag defined for a many-to-many list:

<class name="Author" table="Authors">
    <id name="Id" column="AuthorId">
        <generator class="identity" />
    </id>
    <property name="Name" />
    <bag name="Books" table="Author_Book_Map" where="IsDeleted=0"
fetch="join">
        <key column="AuthorId" />
        <many-to-many class="Book" column="BookId"
where="IsDeleted=0" />
    </bag>
</class>

If I return all author objects (using something like
Session.Query<Author>().List<Author>()), I will get what initially
appeared to be duplicate Author records:

The extra author objects are created when an author is mapped to Book
objects that have IsDeleted = 1 and IsDeleted = 0.  Rather than
creating one Author object with an enumerable that contains only the
books with IsDeleted = 0, it will create two author objects.  The
first author object has a Books enumerable that contains books with
IsDeleted = 0. The second author object will contain an enumerable of
null book
objects.

I'm thinking part of the problem stems from the map table objects
linking to rows that satisfy the where condition on the bag object but
do not meet the many-to-many where condition.

This is using NH 3.0.0.1001.  Is this a configuration issue or
something else?

Thanks,

Jim

Reply via email to