问题描述
- Nhibernate使用CreateCriteria 如何实现 exists
-
public IList<Customer> QueryAllCustomerHasOrdersByHSql() { return Session.CreateQuery("from Customer c where exists( from Order a where a.Customer=c.Id)").List<Customer>(); } public IList<Customer> QueryAllCustomerHasOrdersBySql() { return Session.CreateSQLQuery("select c.* from Customer c where exists(select b.Customer from `Order` b where b.Customer=c.CustomerId)") .AddEntity("c",typeof(Customer)).List<Customer>(); } //public IList<Customer> QueryAllCustomerHasOrdersByCriteria() { //return Session.CreateCriteria(typeof(Customer)) // .Add(Restrictions.In("Customer",)) //}
如何使用 CreateCriteria Restrictions 实现上面使用SQL的查询功能
解决方案
http://stackoverflow.com/questions/1752792/nhibernate-createcriteria-and-exists-clause
解决方案二:
@苏小喵
谢谢
时间: 2024-10-30 10:54:20