我这里有这个SQL需要转移到NHibernate Criteria API:
select nn.* from NetworkNumber nn
inner join
(select number, max(Version) ver
from NetworkNumber
group by number) b on b.number=nn.number
and b.ver=nn.version
如果有人对它有很好的了解,我会非常感激。在此期间 - 我将继续尝试并回复结果(如果有的话)..
修改 到目前为止,我有这个:
var results = StagingSessionFactory.OpenSession()
.CreateCriteria<NetworkNumber>()
.SetProjection(
Projections.ProjectionList()
.Add(Projections.Property("Number"), "Number")
.Add(Projections.Max("Version"), "Version")
.Add(Projections.GroupProperty("Number"), "Number")
)
.SetResultTransformer(Transformers.AliasToBean(typeof(NetworkNumber)))
.List<NetworkNumber>();
这给了我正确的版本/ NetworkNumber的编号,但我需要其余的字段(Id等)。也许我只是遗漏了一些东西?