I have a read-only mssql-view, and I want to map it to nhibernate (using hbm.xml files).
The view is a select that joins two tables. For give an abstract-insight, the select is something like this:
SELECT A.Id As A_ID, B.Id As B_ID,
A.AttributeA, B.AttributeB,
FROM A INNER JOIN B ON
A.Id = B.RootID
It’s a one-to-many relationship between A and B (B entries are dependant/leafs of A entries).
I’m using nhibernate’s hbm.xml files, and I can’t make it to work.
I’d gladly appreciate if someone can enlight me of the kind of XML that I have to use, I guess that as my view has no ID, I have to create a composite-nhibernate id (wich will be the ids os A and B together) but I couldn’t make it to work.
Also the view is READ ONLY so I think that should make the solution easier.
I’m asking the question because none of the others on the site answered this issue (some use fluent-nhibernate,I’m with XML mapping files)
thanks in advance.
Thanks to Andy, that lead me to the final solution.
I will put the hbm.xml template with my domain-model entities.
All the columns I’m mapping are varchars/strings (hence my composite ID consist of two strings):
But the mapping was not enough. Nhibernate requests to Override the
EqualsandGetHashCodefunction, I will put the exact code of my working VB.Net class that correspond to this XML: