0
我有以下的ICriteria查詢,NHibernate的生成正確的SQL,但返回空行
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();
}
而且它產生以下SQL。
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 */
當我從我的應用程序運行查詢nHibernate返回適量的行,但所有的字段爲空或空。但是當我使用它生成的SQL(來自nhibernate分析器)並在我的db上運行它時,它會返回正確的結果。
我在做什麼錯誤/缺失?
參見[這個問題](HTTP:// stackoverflow.com/questions/2146637/return-entity-via-projection-query)。 – 2010-03-01 16:21:58