Hi
Here are classes and mapping for CigEntity and CigEntityDP
----- CigEntity -----
Code:
using System;
using System.Collections;
using System.Xml.Serialization;
using CigFramework.ValueObject.Base;
using ValueObjects.General.Address;
using ValueObjects.General.Company;
using ValueObjects.General.Identification;
using ValueObjects.General.Individual;
using ValueObjects.General.Phone;
namespace ValueObjects.General
{
/// <summary>
/// Implementation of the ICigEntity interface.
/// </summary>
[Serializable]
public class CigEntity
{
private bool isSearchable;
private int providerId;
private int originId;
private int cId;
private bool disabled;
/// <summary>
/// Default constructor.
/// </summary>
public CigEntity()
{
}
/// <summary>
/// Tells if the entity appears in search results
/// </summary>
public bool IsSearchable
{
get { return isSearchable; }
set { isSearchable = value; }
}
/// <summary>
/// Id of the subscriber that provided the information
/// </summary>
public int ProviderId
{
get { return providerId; }
set { providerId = value; }
}
/// <summary>
/// Id of the origin of the entity
/// </summary>
public int OriginId
{
get { return originId; }
set { originId = value; }
}
/// <summary>
/// The Creditinfo Id used to identify the object
/// </summary>
public int CId
{
get { return cId; }
set { cId = value; }
}
/// <summary>
/// Indicates wether the object is disabled or enabled. If the object is disabled the value is true.
/// </summary>
public bool Disabled
{
get {return disabled; }
set { disabled = value; }
}
}
[Serializable]
public class CigEntityIndividual : CigEntity
{
private IIndividual _individual;
#region ICigEntityIndividual Members
/// <summary>
/// Get or sets an instance of Individual entity.
/// </summary>
public IIndividual Individual
{
get
{
return _individual;
}
set
{
_individual = value;
}
}
#endregion
}
[Serializable]
public class CigEntityCompany : CigEntity
{
private ICompany _company;
#region ICigEntityCompany Members
/// <summary>
/// Gets or sets an instance of Company entity.
/// </summary>
public ICompany Company
{
get
{
return _company;
}
set
{
_company = value;
}
}
#endregion
}
}
---- CigEntity.hbm.xml ----Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ValueObjects.General.CigEntity, ValueObjects" table="c_ge_CigEntity" discriminator-value="-99">
<id name="CId" column="CId" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<discriminator column="Type" type="Int32"/>
<property name="IsSearchable" column="IsSearchable" type="Boolean"/>
<property name="ProviderId" column="ProviderId"/>
<property name="OriginId" column="OriginId"/>
<property name="Disabled" column="Disabled" type="Boolean"/>
<subclass name="ValueObjects.General.CigEntityIndividual, ValueObjects" discriminator-value="1">
<many-to-one name="Individual" class="ValueObjects.General.Individual.Individual, ValueObjects" column="CId" insert="false" update="false"/>
</subclass>
<subclass name="ValueObjects.General.CigEntityCompany, ValueObjects" discriminator-value="2">
<many-to-one name="Company" class="ValueObjects.General.Company.Company, ValueObjects" column="CId" insert="false" update="false"/>
</subclass>
</class>
</hibernate-mapping>
---- CigEntityDP ----Code:
using System;
using System.Collections;
using System.Xml.Serialization;
namespace ValueObjects.DP.General
{
[Serializable]
public class CigEntityDP : ValueObjects.General.CigEntity
{
private int type;
/// <summary>
/// The Id of the type
/// </summary>
public int Type
{
get { return type; }
set { type = value; }
}
}
[Serializable]
public class CigEntityIndividualDP : CigEntityDP
{
private Individual.IIndividualDP individual;
/// <summary>
/// Default constructor - sets the type of CigEntity
/// </summary>
public CigEntityIndividualDP()
{
Type = 1;
}
/// <summary>
/// The Individual
/// </summary>
public Individual.IIndividualDP Individual
{
get { return individual; }
set { individual = value; }
}
}
[Serializable]
public class CigEntityCompanyDP : CigEntityDP
{
private Company.ICompanyDP company;
/// <summary>
/// Default constructor - sets the type of CigEntity
/// </summary>
public CigEntityCompanyDP()
{
Type = 2;
}
/// <summary>
/// The Company
/// </summary>
public Company.ICompanyDP Company
{
get { return company; }
set { company = value; }
}
}
}
---- CigEntityDP.hbm.xml ----Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ValueObjects.DP.General.CigEntity, ValueObjects" table="c_dp_CigEntity" discriminator-value="-99">
<id name="CId" column="CId" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<discriminator column="Type" type="Int32"/>
<property name="IsSearchable" column="IsSearchable" type="Boolean"/>
<property name="ProviderId" column="ProviderId"/>
<property name="OriginId" column="OriginId"/>
<property name="Disabled" column="Disabled" type="Boolean"/>
<subclass name="ValueObjects.DP.General.CigEntityIndividualDP, ValueObjects" discriminator-value="1">
<many-to-one name="Individual" class="ValueObjects.DP.General.Individual.Individual, ValueObjects" column="CId" insert="false" update="false"/>
</subclass>
<subclass name="ValueObjects.DP.General.CigEntityCompanyDP, ValueObjects" discriminator-value="2">
<many-to-one name="Company" class="ValueObjects.DP..General.Company.Company, ValueObjects" column="CId" insert="false" update="false"/>
</subclass>
</class>
</hibernate-mapping>
The code I used to load a list of CigEntity is the following
ICriteria criteria = session.CreateCriteria(CigEntity);
criteria.SetMaxResults(maxReadResults);
//Some other criteria
IList results = criteria.List();
return results;
If I look at the sql generated then the table c_dp_CigEntity is used instead if c_ge_CigEntity
If i remove the CigEntityDP.hbm.xml from the project then it works fine - also if I load a single CigEntity with Load
Regards,
Haukur