1

所以我是来自 EF 的 Nhibernate 新手。在尝试了 Query<> 并因缺乏受支持的函数和无意义的 sql 而感到不知所措后,我正在尝试 QueryOver 但还没有走远。有人可以帮我用这个 SQL 的 QueryOver 表示吗?

select p2.* from
   PurchaseOrders p2 inner join 
   (SELECT po.PurchaseOrderID, MAX(POS.StatusDate) as LastUpdate FROM PurchaseOrders Po 
   inner join PurchaseOrderStatuses POS on PO.PurchaseOrderID = pos.PurchaseOrderID 
   where pos.StatusID = :@status and po.SupplierID = :@supplierId
   group by po.PurchaseOrderID) p1
   on p2.PurchaseOrderID = p1.PurchaseOrderID
4

1 回答 1

0

当前的解决方案看起来像这样,但需要进一步的工作:

 int supplierId = 20;
         Status.StatusesEnum status = Status.StatusesEnum.Complete;

         PurchaseOrder orderAlias = null;

         IList<PurchaseOrder> orders =
                 Session.QueryOver<PurchaseOrder>(() => orderAlias).WithSubquery
                   .WhereExists(QueryOver.Of<PurchaseOrderStatus>()
                      .Where(c => c.PurchaseOrder.Id == orderAlias.Id)
                      .OrderBy(c=>c.StatusDate)
                      .Desc
                      .Select(c=>c.Status.Id == (int)status)
                      .Take(1)
                      //.Having status = statusID
                      )
                   .Where(o=>o.Supplier.Id == supplierId)
                   .List<PurchaseOrder>();
于 2012-07-10T14:06:44.853 回答