dado2003 wrote:
post some mappings and source code...
Hi dado2003!
The code:
Code:
public static IList ListByExample(object example)
{
ICriteria criteria = NHibernateHelper.GetSession().CreateCriteria(example.GetType());
Example sample = Example.Create(example);
sample.ExcludeZeroes();
sample.ExcludeNulls();
criteria.Add(sample);
return criteria.List();
}
The mapping:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="MapOR.Contato,MapOR" table="contato">
<composite-id access="field">
<key-property name="EmpId" column="EMP_ID" type="Int32" />
<key-property name="PesId" column="PES_ID" type="String"/>
<key-property name="ConId" column="CON_ID" type="Int32" />
</composite-id>
<property column="CON_NOME" type="String" name="ConNome" not-null="true" length="50" />
<property column="CON_FONE1" type="String" name="ConFone1" length="12" />
<property column="CON_FONE2" type="String" name="ConFone2" length="12" />
<property column="CON_FAX" type="String" name="ConFax" length="12" />
<property column="CON_RAMAL" type="String" name="ConRamal" length="5" />
<property column="CON_DEPARTAMENTO" type="String" name="ConDepartamento" length="50" />
<property column="CON_HOMEPAGE" type="String" name="ConHomepage" length="50" />
<property column="CON_EMAIL" type="String" name="ConEmail" length="50" />
<property column="CON_DTANIVERSARIO" type="DateTime" name="ConDtaniversario" />
</class>
</hibernate-mapping>
When I try to do this:
Code:
Contato c = new Contato();
c.EmpId = 1;
c.PesId = 1;
IList lista = ListByExample(c);
The variable "lista" will receive all records from the table "contato". The filter EmpId and PesId isn't being used.