3
基本上,我一直在努力做到這一點(基於兩列數不同):NHibernate的數不同(基於多列)
select count(distinct(checksum(TableA.PropertyA, TableB.PropertyB)))
from TableA
left outer join TableB
on TableA.TableBId = TableB.Id
where PropertyA like '%123%'
被谷歌搜索上如何做到這一點,但沒有運氣。試過這個,但從來沒有真正的工作。這並不明顯基於這兩個屬性從兩個表計數:
var queryOver = c.QueryOver<TableA>();
TableB tableBAlias = null;
TableA tableAAlias = null;
ProjectionList projections = Projections.ProjectionList();
queryOver.AndRestrictionOn(x => x.PropertyA).IsLike("%123%");
projections.Add(Projections.CountDistinct(() => tableAAlias.PropertyA));
queryOver.JoinAlias(x => x.TableB ,() => tableBAlias, JoinType.LeftOuterJoin);
projections.Add(Projections.CountDistinct(() => tableBAlias.PropertyB));
queryOver.Select(projections);
queryOver.UnderlyingCriteria.SetProjection(projections);
return queryOver.TransformUsing(Transformers.DistinctRootEntity).RowCount();
RegisterFunction(「校驗」,新SQLFunctionTemplate(NHibernateUtil.Int32,「校驗(?1,?2 )「))這個主題很棒! –
@ eaon21:很高興幫助! –