有了这个查询,我得到一个 InvalidOperationException:“应用单一聚合的集合必须为空或只包含一个项目”。
List<int> olsesUsedForTaskCompletion = new List<int>();
olsesUsedForTaskCompletion.AddRange(task.OrderLineSpecifications_QtysCompleted.Select(ols => ols.Key).ToList());
var allRelatedTasks = (from t in new XPQuery<Core.Model.Task.Task>(session, true)
join ols in new XPQuery<OrderLineSpecification>(session, true)
on t.PickSpecification equals ols.PickSpecification
where t.PickSpecification == task.PickSpecification
&& t.Status != TaskStatuses.Cancelled
&& olsesUsedForTaskCompletion.Contains(ols.Oid)
select t).ToList();
我希望在加入时仅获取具有特定 ID 的 OLS。我究竟做错了什么?
这是堆栈跟踪:
at DevExpress.Xpo.Helpers.InTransactionLoader.ProcessException(Exception ex)
at DevExpress.Xpo.Helpers.InTransactionLoader.ProcessAnalyzeAndExecQuery()
at DevExpress.Xpo.Helpers.InTransactionLoader.Process()
at DevExpress.Xpo.Helpers.InTransactionLoader.GetObjects(ObjectsQuery[] queries)
at DevExpress.Xpo.Helpers.InTransactionLoader.GetObjects(Session session, ObjectsQuery[] queries)
at DevExpress.Xpo.Session.<>c__DisplayClass16.<GetObjectsInTransaction>b__14()
at DevExpress.Xpo.Logger.LogManager.Log[T](String category, LogHandler`1 handler, MessageHandler`1 createMessageHandler)
at DevExpress.Xpo.Session.GetObjectsInTransaction(XPClassInfo classInfo, CriteriaOperator condition, SortingCollection sorting, Int32 skipSelectedRecords, Int32 topSelectedRecords, Boolean selectDeleted)
at DevExpress.Xpo.XPQueryBase.SessionGetObjects(XPClassInfo classInfo, CriteriaOperator condition, SortingCollection sorting, Int32 skipSelectedRecords, Int32 topSelectedRecords, Boolean selectDeleted)
at DevExpress.Xpo.XPQueryBase.GetObjects()
at DevExpress.Xpo.XPQueryBase.Enumerate(Type type)
at DevExpress.Xpo.XPQuery`1.GetEnumerator()
at DevExpress.Xpo.XPQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Davanti.WMS.Services.Implementation.Outbound.OrderLineSpecificationStatusService.ChangeStatusToPickedToShipToStageOrStaged(Session session, IList`1 tasks, IList`1 olsWithoutTasks) in c:\Corax\DAV_WMS\DEV\SRC\APP\WMS\Davanti.WMS.Services.Implementation\Outbound\OrderLineSpecificationStatusService.cs:line 471
更新:经过一番挣扎后,我所做的是: - 采用了另一种方法。我不知道您是否可以获取它的业务逻辑,但我首先使用 OLS 生成了一个列表,然后从中生成了另一个带有选择规范的列表。后来我对Tasks做了一个简单的查询。
// compose list of olses for which status will be updated
List<OrderLineSpecification> olSpecs = (from ols in new XPQuery<OrderLineSpecification>(session, true)
where ols.Status != OrderLineSpecificationStatus.Cancelled
//...
&& ols.PickSpecification == task.PickSpecification
&& (olsesUsedForTaskCompletion.Count == 0
|| (olsesUsedForTaskCompletion.Contains(ols.Oid) && ols.QtyOrdered == ols.QtyPicked))
select ols).ToList();
var pickSpecificationKeys = (from ols in olSpecs select ols.PickSpecification.Oid).Distinct().ToList();
var allRelatedTasks = (from t in new XPQuery<Core.Model.Task.Task>(session, true)
where pickSpecificationKeys.Contains(t.PickSpecification.Oid)
&& t.Status != TaskStatuses.Cancelled
select t).ToList();
我只是希望这能奏效,无论客户的数据库结构,双重引用等等...... :)