I'm sorry if this post already exists somewhere but I read that the search tool was not working and I realy need help with this one.
I got this situation. I have 2 classes : Campaign, Customer with share a relation one-to-many. So I created this mapping
Code:
<class name="Campaign" table="campaign" lazy="true">
<id name="campaignName" column="campaignname" type="String">
<generator class="assigned">
</id>
<bag name="Customers" cascade="all-delete-orphan" lazy="true">
<key column="campaignname">
<one-to-many class="Customer" />
<bag>
<property column="Description" type="String" name="Description" not-null="true" length="31" />
</class>
<class name="Customer">
<composite-id access="field" >
<key-property name="CampaignName" column="campaignname" type="String"/>
<key-property name="FirstName" column="firstName" type="String"/>
</composite-id>
<many-to-one name="Campaign" class="Campaign" column="campaignname" />
<property column="LastName" type="String" name="LastName" not-null="true" length="15" />
</class>
In my c# classes, I created an IList<Customer> in my Campaign object in order to have my collection of Customers. I also created a Campaign object in my Customer class to have access to my campaign at my customer level.
I faced now this issue :
When I try to lazy load my campaign information from my customer object it works. ie:
Code:
ICriteria criteria = session.CreateCriteria(typeof(Customer));
criteria.Add(Expression.Eq("CampaignName", "ES3000J2"));
criteria.Add(Expression.Eq("FirstName", "Julian"));
List<Customer> list = (List<Customer>)criteria.List<Customer>();
if (list.Count > 0)
{
Console.WriteLine("Customer Last Name: " + list[0].LastName);
Console.WriteLine("Campaign desc : " + list[0].Campaign.Description);
}
But when I tried to access my customers from my campaign it did not work :
Code:
Campaign test = session.Get<Campaign>("ES3000J2");
Console.WriteLine("#customer : " + test.Customers.Count);
Customers.Count is always 0
What am I missing ?