gpt4 book ai didi

c# - 检索最近 5 个订单的单位

转载 作者:IT王子 更新时间:2023-10-29 06:29:52 26 4
gpt4 key购买 nike

引用:nhibernate criteria for selecting from different tables

我试图检索例如最后 5 个订单,但我得到了最后 5 个单位!

Model.Order orderAlias = null;
Model.Unit unitsAlias = null;
Model.Employee employeeAlias = null;

IList<Model.Unit> itemList = null;

using (m_hibernateSession.BeginTransaction())
{
var query = m_hibernateSession.QueryOver<Model.Unit>(() => unitsAlias)
.JoinAlias(() => unitsAlias.OrderRef, () => orderAlias, JoinType.InnerJoin)
.JoinAlias(() => unitsAlias.EmployeeRef, () => employeeAlias, JoinType.InnerJoin);

// add additional filters if set
if (propertiesNames.Keys.Contains("Employee")) query.Where(Restrictions.On(() => employeeAlias.Name).IsLike( "%" + (string)propertiesNames["Employee"] + "%"));
if (propertiesNames.Keys.Contains("Division")) query.Where(() => unitsAlias.Division == (string)propertiesNames["Division"]);

query.Where(() => orderAlias.PONumber != 0).OrderBy(() => orderAlias.PONumber).Desc.Take(5);

itemList = query.List<Model.Unit>();
}

获取最近 5 个订单的单位需要进行哪些更改?

谢谢

最佳答案

试试这个:

    //A List (with a maximum of 5 elements) of Lists of Units
List<List<Model.Unit>> listOfUnits = m_hibernateSession
.Query<Order>()
.OrderByDescending(o=>o.PONumber)
.Where(o => o.PONumber != 0)
.Take(5)
.Select(o => o.Units.ToList())
.ToList();

//OR, a List of all Units for the last 5 Orders
List<Model.Unit> listOfUnits = m_hibernateSession
.Query<Order>()
.OrderByDescending(o=>o.PONumber)
.Where(o => o.PONumber != 0)
.Take(5)
.SelectMany(o => o.Units)
.ToList();

关于c# - 检索最近 5 个订单的单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16773947/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com