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的查询功能

0

2个回答

1

@苏小喵
谢谢

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!