I have my application liek this:
I have user track this product, so class Track
Note multiple user can track one product, so the relationship between Product : Track is 1 : n
However, if user is currently signed in, it can only be 1 Track associated to Product, and in my list page, I should display a list of products with its track status for current user, something like:
Product A - Tracked on 2011-01-01
Product B - Not Tracked
Product C - Tracked on 2010-12-20
...
Thus in plain sql, I may have a query like this:
Code:
select * from Product as p
left outer join Track as t
on t.ProductId = p.Id and t.UserId = {currentUser.Id}
But using NHibernate I find it not easy to implement, currently I have a ProductWithTrack class, which inherits from Product class and adds a Track property:
Code:
class ProductWithTrack : Product {
Track track;
}
My effort is to map this class to Product table just the same as Product class, but how can I figure the mapping of Track property, I have tried:
one-to-many, but Track is not a collection
many-to-one / one-to-one, this requires a foreign key column in Product table which certainly not exists
Please help in this mapping problem, thanks.