J'ai la requête ICriteria suivante,NHibernate générer SQL correcte, mais le retour des lignes vides
public override IQueryable<ApplicationVehicleSummary> GetQuery(ISession session)
{
ICriteria results = session.CreateCriteria<Part>()
.Add(Restrictions.Eq("PartNumber", _partNumber))
.CreateCriteria("Applications")
.CreateAlias("Vehicles", "vehicle", global::NHibernate.SqlCommand.JoinType.InnerJoin)
.SetProjection(Projections.Property("vehicle.Make"),
Projections.Property("vehicle.Model"),
Projections.Property("vehicle.Type"),
Projections.Property("vehicle.Engine"),
Projections.Property("vehicle.ProductionStart"),
Projections.Property("vehicle.ProductionEnd"))
.SetResultTransformer(Transformers.AliasToBean<ApplicationVehicleSummary>());
return results.List<ApplicationVehicleSummary>().AsQueryable();
}
et produit l'instruction SQL suivante.
SELECT vehicle2_.Make as y0_,
vehicle2_.Model as y1_,
vehicle2_.Type as y2_,
vehicle2_.Engine as y3_,
vehicle2_.ProductionStart as y4_,
vehicle2_.ProductionEnd as y5_
FROM Parts this_
inner join Applications applicatio1_
on this_.PartId = applicatio1_.PartId
inner join VehiclesToApplications vehicles5_
on applicatio1_.ApplicationId = vehicles5_.ApplicationId
inner join Vehicles vehicle2_
on vehicles5_.VehicleId = vehicle2_.VehicleId
WHERE this_.PartNumber = '0500-252' /* @p0 */
Quand je lance la requête de mon application NHibernate retourne la bonne quantité de lignes, mais tous les champs sont nuls ou vides. Mais quand je prends le SQL qu'il a généré (à partir de nhibernate profiler) et l'exécute sur ma base de données, il renvoie les résultats corrects.
Qu'est-ce que je fais de mal/manque?
Voir [cette question] (http: // stackoverflow.com/questions/2146637/return-entity-via-projection-query). –