I am a developer from Florida, USA. We are big fans of NHibernate
(3.3.1.4000) and also we are very happy to work with the .NET version. We
recently found something but we are not sure if it is bug. We have made
several test with different variants but still got the same unwanted
results. This is the description:
We need to map 3 tables to one class with Mapping By Code using the fluent
API.
This is the basic mapping for the principal table
// schema
Schema("dbo");
// table
Table("TEST_Principal");
// id
Id(i => i.Id, m => m.Column("PrincipalID"));
and we want to get properties from two more tables. So we do
Join(
"TEST_PrincipalExtra",
m => {
m.Key(k => { k.Column("PrincipalExtraID"); });
m.Property(i => i.Prop1, n => { n.Column("Column1"); });
});
// and
Join(
"TEST_Principal_Aud",
m => {
m.Key(k => { k.Column("Principal_AudID"); });
m.Component(i => i.AuditInformation);
});
Based on the output from NHibernate profiler we get:
select
/// properties here
from
TEST_Principal p inner join
TEST_PrincipalExtra pe on p.PrincipalID = a.Principal_AudID inner join
TEST_Principal_AuditID a on p.PrinciaplID = a.Principal_AudID
Notice how it correctly gets the tables for the join and also it associates
correctly the columns from each table. But the m.Key statement from the
second join overrides the previous one and makes the query fail because the
ID for TEST_PrincipalExtra is not Principal_AudID. We have found that if
you swap the order of the join statements then we get the same error but
now on TEST_Principal_Aud. So NHibernate stays with the last Key statement.
But if we do the mapping on xml it works perfectly.
<hibernate-mapping xmlns="urn:nhibernate-mapping-
2.2">
<class name="TESTPrincipalClass" table="TESTPrincipal">
<id name="Id" column="PrincipalID" />
<join table="TEST_PrincipalExtra">
<key column="PrincipalExtraID" />
<property name="Prop1" column="Column1" />
</join>
<join table="TEST_Principal_Aud">
<key column="Principal_AudID" />
<component name="AuditInformation" />
</join>
</class>
</hibernate-mapping>
Thanks for your time.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/nhusers/-/57X8CWmXtagJ.
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.