需要将此sql查询转换为nhibernate准则语言...我该怎么做?
select
*
from Feeds where Id =
(select MAX(Id) from Feeds where DataId = [VARIABLE PARAMETER])
答案 0 :(得分:2)
Feed feed = _session.CreateCriteria<Feed>()
.Add(Restrictions.Eq("DataId", "[VARIABLE PARAMETER]"))
.AddOrder(new Order("_id", false))
.SetMaxResults(1)
.List<Feed>()
.FirstOrDefault();
这将导致类似:
select TOP 1 * from Feeds where DataId = ??? Order By Id desc
从性能的角度来看,应该没有difference。