I'm trying to map a table back to itself in a many-to-many
collection.  The table involved stores information about an entity
across multiple environments.  The entities are related by a common
key which they share across environments.  Basically, for every row in
the Entity table there will be a unique pairing of EnvironmentId and
CommonKey but there can be multiple entries with the same CommonKey.
I want to setup a set that will get all Entities with the same common
key.

table Entity (
        EntityId uniqueidentifier not null,
        CommonKey nvarchar(36) not null,
        EnvironmentId uniqueidentifier not null
)

public class Entity
{
        public virtual Guid Id { get; set; }
        public virtual string CommonKey { get; set; }
        public virtual Guid EnvironmentId { get; set; }

        public virtual ISet<Entity> RelatedEntities { get; set; }
}

<class name="Testing.Entity, Testing" table="Entity">
        <id column="EntityId" name="Id">
                <generator class="guid" />
        </id>

        <property name="CommonKey" />
        <property name="EnvironmentId" />

        <set name="RelatedEntities" table="Entity">
                <key column="SOMETHING" property-ref="SOMETHING" />
                <many-to-many column="SOMETHING" class="Testing.Entity, 
Testing" />
        </set>
</class>

The SQL I would use to get this is:

select entity1.EntityId, entity1.CommonKey, entity1.EnvironmentId,
entity2.EntityId, entity2.CommonKey, entity2.EnvironmentId
from Entity entity1
left outer join Entity entity2 on entity1.CommonKey =
entity2.CommonKey
where entity1.EntityId = ?

It seems that property-ref should enable this but I cannot figure out
the correct combination of columns and property names for the set
mapping.  I have tried this with NHibernate 2.0 and 2.1 with similar
results.  Is this a supported scenario with NHibernate?  If so, how do
I setup the mapping for the set?

Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to