Summary: I am having difficulty retrieving data from a single table if I have 2 related tables (current and history data), that map to different C# classes, but the historical C# class inherits from the current C# class. If I retrieve using the current data class, I'm getting both current and historical data.
Explanation:I'm going to try explaining this with words, but the sample code at the end of the posting probably make more sense. Here's what is happeniing:
1. Have 2 tables, 'Pay', 'PayHist' with subclasses using the table per class hierachy.
2. The base class and subclasses for the current and history data have all different C# class names. The mapping files reflect this.
3. Since the current and history classes have some common functionality, I have the history class inherit from the corresponding current class. For example, CreditHist inherits from Credit
Problem: When retrieving data using the current subclasses, ie Credit, I am also getting data from the current AND history tables.
Question: Since my CreditHist (which is mapped to table PayHist) is inheriting from Credit which is inheriting from Pay (which is mapped to table pay) does NHibernate ignore the xml mapping of CreditHist which is using the table PayHist and replace it with the mapping of Credit which is using the table Pay? If that's the case is there a different way to define these classes?
Actually I'm hoping this falls in the "it's such an obvious error" category and there's a simple solution.
Thanks for your help.
Diane
-----------------------------------------------------------------------
Here is some sample code demonstrating the problem:
Class Defintions -----
My Pay table class definitions are similar to this:
Code:
class Pay...
class Credit: Pay, ICredit
class Cash: Pay...
My PayHist table class definitions are similar to this:
Code:
class PayHist...
class CreditHist: Credit
class CashHist: Cash
Mappings -----
For the table Pay:
Code:
... <class name="Domain.Pay" table="Pay" discriminator-value="0" >
<id name="Id" column="ID" type="int" >
<generator class="assigned"/>
</id>
<discriminator
formula="(select n.subclass_name from numeric_code n where n.unique_id = TYPE_ID)"
type="String"
/>
...
<subclass name="Credit"
discriminator-value="CreditCardPayment">
</subclass>
<subclass name="Cash"
discriminator-value="CashPayment">
</subclass>
...
For the table PayHist:
Code:
...
<class name="Domain.PayHist" table="PayHist" discriminator-value="0" >
<id name="Id" column="ID" type="int" >
<generator class="assigned"/>
</id>
<discriminator column="PAYMENT_CLASS_NAME"
/>
...
<subclass name="CreditHist"
discriminator-value="CreditCardPayment">
</subclass>
<subclass name="CashHist"
discriminator-value="CashPayment">
</subclass>
...