微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 如何修复“应用单个聚合的集合必须为空或者只包含一个项目”InvalidOperationException?

有了这个查询,我得到一个InvalidOperationException:“应用Single聚合的集合必须为空或者只包含一个项目”.

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,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();

我只希望这会工作,无论客户的数据库结构,duble参考还是……

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐