Hi
I'm just another beginner in need of help ;)
Reading NHibernate's documentation I've found "Component mapping" feature which maps child properties to parent's row. I need something inverted - I'd like to have data from child row mapped to the parent object. How to do this?
Here is detailed description of my problem:
I have many-to-many asociation between Products and Customers (there are some limitations in product 'visibility' for some customers, prices are different too). So, in fact, I have 3 classes:
Code:
class Product
{
int Id
string Name
string PartNumber
}
class Customer
{
int Id
string Name
string Code
}
class P2CLink
{
int Id
Product Product
Customer Customer
decimal Price
string CustomersPartNumber
}
All of these objects are stored in tables: Products, Customers, P2CLinks.
Mapping schema of the first two is obvious, P2CLink has following mapping:
Code:
<class name="P2CLink" table="P2CLink">
<id name="Id">
<column name="Id" sql-type="int" not-null="true"/>
<generator class="identity" />
</id>
<many-to-one class="Product" name="Product" fetch="join" column="ProdId"/>
<many-to-one class="Customer" name="Customer" fetch="join" column="CustId"/>
<property name="Price" formula="GetPrice(ProdId,CustId)" type="string"/>
</class>
What I need is to display Pricelist for given Customer with ability to make some filtration or search by the Part Number or Customer's Part Number.
I've made a 'view' which inherits P2CLink as following
Code:
class NiceP2CLinkView:P2CLink
{
string Name {return Product.Name;}
string PartNumber {return product.PartNumber;}
}
So, the pricelist now looks ok, but... performing a query is a little bit frustrating - I can't query for "view" properties, so I have to build some nasty nested criteria for querying for Product or for Customer.
I think, there has to be some simpler and cleaner solution, however I have no idea how to get it in the other way.
============
Edit: Ops, I forgot It's NHibernate 1.2 and .NET 2.0 (C#)