I've got a Recipe class, that contains lists of three different types
of Ingredient Uses. These classes all inherit from the base,
IngredientUse. So the mapping for the IngredientUse looks like this:

  <class name="IngredientUse" table="IngredientUses">
    <id name="Id" type="Int64" column="Id">
      <generator class="native"/>
    </id>
    <!--some other properties-->
    <property name="RecipeId" column="RecipeId"/>
    <joined-subclass name="AdditionUse" table="AdditionUses">
      <key column="Id" foreign-key="FK_AdditionUses_IngredientUses"/>
      <many-to-one name="AdditionUsed" column="AdditionUsed"
class="Addition" foreign-key="FK_AdditionUses_Additions"/>
    </joined-subclass>
  </class>

The one causing problems here is the RecipeId. From the recipe, I have
three separate lists of uses for different ingredient types, defined
like so:

<bag name="AdditionsUsed" cascade="all" lazy="false">
  <key column="RecipeId"/>
  <one-to-many class="AdditionUse"/>
</bag>

Now, I'm running into problems trying to load these lists. It has
something to do with the inheritance. When I look at the SQL
Generated, I see this:

SELECT additionsused0_.RecipeId as RecipeId1_
--other columns not really important
FROM AdditionUses additionsused0_
inner join IngredientUses additionsused0_1_
on additionsused0_.Id=additionsused0_1_.Id
WHERE additionsused0_.recipe...@p0; @p0 = '11'

Not sure if it matters but just to be thorough the database is SQL
2008 (using the 2005 dialect).

Notice that its' looking for the RecipeId in the subclass' table, and
not the base table where the column is actually contained. I know I
could just define a separate table for each ingredient type, but that
will cause me problems because there are some situations (ie pricing)
where I don't need the additional columns in the subclass table, and
would like to be able to load all the ingredients into the same list
at once.

Is it not possible to link to a subclass in a one-to-many, referencing
one of the properties from the base?  That is kind of what I've heard
elsewhere, in not so many words.  If this is not possible, what other
options do I have?  A separate table for each class is not good for
me, so I was thinking of making everything in the same table, with
nullable columns for everything in the subclasses, and then using a
SubTypeId enum or something like that (and just sorting them out in
the client most likely).  I'd really prefer to avoid this if possible.

I'm certain I must be missing something here, figured someone more
familiar with the NHibernate framework might recognize it right off
the bat.

TIA

Alex

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