代码
IList VendorList;
VendorList = session
.CreateCriteria<VendorLookup>()
.Add(Expression.Eq("NetworkRunId", networkRunId))
.Add(Expression.Not(Expression.Eq("VendorName", " ")))
.SetResultTransformer(new NHibernate.Transform.DistinctRootEntityResultTransformer())
.AddOrder(new Order("VendorName", true))
.List<IVendorLookup>().Distinct<IVendorLookup>().ToList();
生成的查询请帮我解决
SELECT this_.Sp as HCO1_25_0_,
this_.NID as Network2_25_0_,
this_.Vname as HCO3_25_0_
FROM HCO_V_Lookup this_
WHERE this_.NID = 5 /* @p0 */
and not (this_.VNAME = ' ' /* @p1 */)
ORDER BY this_.VNAME asc
答案 0 :(得分:0)
我认为你想知道为什么DISTINCT
没有出现在SQL中。这是因为它在您的条件查询中作为结果转换器应用 - 在查询运行后,SQL查询结果被过滤以使它们不同。
答案 1 :(得分:0)
ICriteria criteria = session.CreateCriteria(typeof(Person));
criteria.SetProjection(
Projections.Distinct(Projections.ProjectionList()
.Add(Projections.Alias(Projections.Property("FirstName"), "FirstName"))
.Add(Projections.Alias(Projections.Property("LastName"), "LastName"))));
criteria.SetResultTransformer(
new NHibernate.Transform.AliasToBeanResultTransformer(typeof(Person)));
IList people = criteria.List();