简体   繁体   中英

Nhibernate query to get the quantity count joining tables

I need an nhibernate query to get the quantity count . here's my entities. I have a master Inventory table and a Used Inventory table.

public Inventory { Id, Name, Type, ... }

public UsedInventory { Id, Inventory, Quantity, Date, .. }

I am looking for output that look like:

public ResultDTO { Inventory, TotalUsedQuantity }

please help. Thanks

在LINQ中,这很容易:

session.Query<UsedInventory>().GroupBy(x => x.Inventory).Select(x => new ResultDTO { Inventory = x.Key, TotalUsedQuantity = x.Count() }).ToList();

In QueryOver:

ResultDTO dto = null;
var rrr = session.QueryOver<UsedInventory>().SelectList(list => list
.SelectGroup(m => m.Inventory).WithAlias(() => dto.Inventory)
.SelectCount(m => m.Id).WithAlias(() => dto.TotalUsedQuantity)).List<ResultDTO>();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM