문제

SELECT 
  [ProductErpIdentifier], 
  [PriceValue], 
  [ManufacturerProductIdentifier], 
  SUM([QuantityOrdered]) as  [QuantityOrdered]
FROM 
  [eCommerceDev].[dbo].[OrderItem] 
GROUP BY 
  [ProductErpIdentifier],[PriceValue],[ManufacturerProductIdentifier]
ORDER BY  
  [QuantityOrdered] desc

How should I write a CreateCriteria to generate SQL like the example above?

올바른 솔루션이 없습니다

다른 팁

This should do the trick. Due to the fact you did not post your mapping of the orderitem ntity I used the fieldnames as property names. You will need to change OrderItemEntity to your own mapped class, and you need to change the names preceded by oi. by the names of the properties in your class (be aware: these strings are case sensitive!)

var yourResult = Session.CreateCriteria<OrderItemEntity>("oi")
                   .SetProjection(Projections.ProjectionList()
                      .Add(Projections.Alias(Projections.GroupProperty("oi.ProductErpIdentifier"), "ProductErpIdentifier"))
                      .Add(Projections.Alias(Projections.GroupProperty("oi.PriceValue"), "PriceValue"))
                      .Add(Projections.Alias(Projections.GroupProperty("oi.ManufacturerProductIdentifier"), "ManufacturerProductIdentifier"))
                      .Add(Projections.Alias(Projections.Sum("oi.QuantityOrdered"), "QuantityOrdered")))
                   .AddOrder(Order.Desc("QuantityOrdered"))
                   .List();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top