以此查询为例:
select * from publisher
where id not in (
select publisher_id from record
where year = 2008 and month = 4
)
任何人都可以帮助我如何使用NHibernate构建和运行此查询?假设我有两个类:Publisher
和Record
。
由于
答案 0 :(得分:7)
试试这个:
DetachedCriteria c = DetachedCriteria.For<Record>()
.SetProjection(Projections.Property("Publisher"))
.Add(Restrictions.Eq("Year", 2008))
.Add(Restrictions.Eq("Month", 4));
session.CreateCriteria(typeof(Publisher))
.Add(Subqueries.PropertyNotIn("Id", c))
.List();