Hello,

  I have a small hierarchical model as follows

class Behavior {}
class Scenario : Behavior
{
   IList<Behavior> Behaviors {get; set; }   => Many-To-Many
}

Some attributes left out for brevity.
<hibernate-mapping  auto-import="true" default-lazy="false" xmlns:xsd="
http://www.w3.org/2001/XMLSchema"; xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance";

xmlns="urn:nhibernate-mapping-2.2">
  <class name="OneTechnologies.CreditFulfillment.DomainModel.Behavior,
OneTechnologies.CreditFulfillment.DomainModel" table="Behaviors"
discriminator-value="B">
    <cache usage="read-write" />
    <id name="Id" access="property" column="Id" type="Int32"
unsaved-value="0">
      <generator class="native">
      </generator>
    </id>
    <discriminator column="BehaviorType" type="String" />
    <property name="Name" access="property" type="String">
      <column name="Name"/>
    </property>
    <property name="Description" access="property" type="String">
      <column name="Description"/>
    </property>
    <property name="IsDefault" access="property" type="Boolean">
      <column name="IsDefault"/>
    </property>
    <subclass name="OneTechnologies.CreditFulfillment.DomainModel.Scenario,
OneTechnologies.CreditFulfillment.DomainModel" discriminator-value="S">
      <property name="StartDate" access="property" type="System.DateTime,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
        <column name="StartDate"/>
      </property>
      <property name="EndDate" access="property" type="System.DateTime,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
        <column name="EndDate"/>
      </property>
      <bag name="Behaviors" access="nosetter.camelcase-underscore"
table="Behavior_Scenario" lazy="true">
        <key column="ScenarioId" />
        <many-to-many
class="OneTechnologies.CreditFulfillment.DomainModel.Behavior,
OneTechnologies.CreditFulfillment.DomainModel" column="BehaviorId"/>
      </bag>
    </subclass>
  </class>
</hibernate-mapping>

I created the following CTE to load a complete scenario

With ScenarioLoad(Id, BehaviorType, [Name], [Description],
                  IsDefault, StartDate, EndDate,
                  ScenarioId, Depth)
 AS (
    SELECT Id, BehaviorType, [Name], [Description],
           IsDefault, StartDate, EndDate,
           NULL as ScenarioId, 1 as Depth
    FROM Behaviors b WHERE b.BehaviorType = 'S' AND
        NOT EXISTS (
            SELECT bs.ScenarioId from Behavior_Scenario bs
            WHERE bs.BehaviorId = b.Id)
UNION ALL
    SELECT b.Id, b.BehaviorType, b.Name, b.Description,
           b.IsDefault, b.StartDate, b.EndDate,
           bs.ScenarioId, sl.Depth + 1 as Depth
    FROM ScenarioLoad sl
        INNER JOIN Behavior_Scenario bs
            ON sl.Id = bs.ScenarioId
        INNER JOIN Behaviors b
            ON b.Id = bs.BehaviorId
    WHERE b.BehaviorType = 'S'
)
SELECT {query.*}, {b.*}, query.Depth FROM ScenarioLoad query
LEFT JOIN Behavior_Scenario bs ON bs.ScenarioId = query.Id
LEFT JOIN Behaviors b ON b.Id = bs.BehaviorId
ORDER BY Depth

I am trying to create a sql query for this but have failed trying to fetch
the Scenario.Behaviors association.
I have done the following

ISqlQuery query = xxxx
query.AddEntity("query", typeof(Scenario));
query.AddJoin("query.Behaviors", "b");

However I get a nullreference expection in
NHibernate.Loader.Custom.Sql.SQLQueryParser.ResolveProperties(...)
I have had no problem with One-To-Many associations so I must have the
syntax for Many-To-Many wroing

Does ISqlQuery support Many-To-Many and if so how do you describe it.

thanks,
  craig

--~--~---------~--~----~------------~-------~--~----~
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