Hi there,
Here is my domain model:
public class Structure
{
public virtual string Id { get; set; }
public virtual IList<CorporateContact> Contacts { get; set; }
}
public abstract class Contact
{
public virtual Int64 Id { get; set; }
public virtual string Name { get; set; }
}
public class CorporateContact : Contact
{
//...
}
and here is the mapping:
<class name="Structure" table="vStructure" lazy="false">
<id name="Id" column="Id"/>
<bag name="Contacts" table="vCorporateContact" cascade="none" lazy="false">
<key column="Pertinence"/>
<one-to-many class="CorporateContact"/>
</bag>
</class>
<class name="Contact" table="Contact" abstract="true" polymorphism="implicit">
<id name="Id">
<column name="Id"/>
<generator class="identity"/>
</id>
</class>
<joined-subclass name="CorporateContact" table="vCorporateContact"
extends="Contact" abstract="false">
<key column="Id"/>
<property name="Name" column="Name"/>
</joined-subclass>
both the tables vStructure and vCorporateContact table are actually
VIEWS but, as the operations I need to perform on them are just
reading operations, I assume it doesn't matter. Moreover I would just
point out that the 'Pertinence' column in the vCorporateContact view
isn't mapped to any property AND it isn't an actual foreign key to the
Structure table (not my fault, I'm working on a crappy lgeacy db).
When I select a Structure, I have these queries generated from NH (I
removed parameter and made them explicit):
SELECT
structure0_.Id as Id0_0_,
FROM vStructure structure0_
WHERE structure0_.Id = '011300'
SELECT
pertaining0_.Pertinence as Pertinence1_,
pertaining0_.Id as Id1_,
pertaining0_.Id as Id1_0_,
pertaining0_.Name as Name2_0_,
FROM vCorporateContact pertaining0_
inner join
Contact pertaining0_1_
on pertaining0_.Id = pertaining0_1_.Id
WHERE pertaining0_.Pertinence = '011300'
I got the SQL dump for the second query, pasted it on my SQL Server
management console and got 1 record, as expected. BUT if I run the
following snippet:
ISessionFactory sf = ...;
using (var s = sf.OpenSession())
{
var x = s.Get<Structure>('011300');
var count = x.Contacts.Count();
}
the 'count' value is ZERO, and the Structure.Contacts collection is
actually empty.
Any suggestion?
Thanks in advance,
Giulio
--
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
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.