Hello,
En ce moment je suis en train d'essayer de récupérer seulement certains champs particuliers d'une classe/table. Pour se faire j'utilise Criteria avec les projections. Voici le mapping de la classe/table dont je veux récupérer certaines données :
Right now I'm trying to retrieve only specific fields of a class / table.
I use to make Criteria with the projections.
Here is the mapping of the class / table that I want to retrieve some data:
Code :
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<class name="Business.Model.Origination.OrigineElement, Business.Production" table="SystemTableOrigination.TElementOrigine" >
<cache usage="read-write" />
<id name="Id" column="Id" type="System.Int32" unsaved-value="0">
<generator class="native"/>
</id>
<property name="Number" column="Numero" not-null="true" type="System.String"/>
<property name="Description" column="Description" not-null="false" type="System.String"/>
<property name="Observation" column="Observation" not-null="false" type="System.String"/>
<property name="Poids" column="Poids" type="System.String" not-null="false"/>
<property name="Dvd" column="CDDVD" type="System.String" not-null="false"/>
<bag name="DonorTaker" lazy="false" inverse="true">
<key column="ElementOrigineId"/>
<one-to-many class="Business.Model.DonorTaker.DonorTaker, Business.Production"/>
</bag>
</class>
</hibernate-mapping>
The class :
Code :
Code:
[DataContract]
public class OrigineElement : Business.Model.Production.Common.EntityBase, IElement
{
[DataMember] public virtual string Number { get; set; }
[DataMember] public virtual string Description { get; set; }
[DataMember] public virtual string Observation { get; set; }
[DataMember] public virtual IList<Business.Model.DonorTaker.DonorTaker> DonorTaker { get; set; }
[DataMember] public virtual string Poids { get; set; }
[DataMember] public virtual string Dvd { get; set; }
}
My criteria :
Code :
Code:
ICriteria crit = session.CreateCriteria(OrigineElement)
.Add(Projections.Alias(Projections.Property("Number"), "Number"))
.Add(Projections.Alias(Projections.Property("Description"), "Description"))
.Add(Projections.Alias(Projections.Property("DonorTaker"), "DonorTaker"))
.Add(Restrictions.Eq("Id", "50"));
crit.SetResultTransformer(
new NHibernate.Transform.AliasToBeanResultTransformer(OrigineElement));
result = (OrigineElement)crit.UniqueResult();
the result returns me an object property with the right number, the correct description by my cons list DonorTaker type object is null then what should contain more objects.
It's here i have a problem !
Thx !
Bye
PS : sorry if my language is horrible, but i am french ;)