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