0

当我将 BarCodeId FK 更改为允许 ContactDocument 中的 null 时。之后,如果 ContactDocument 中的任何实体的 BarCodeId 为空,我就会开始在客户端出现错误。如果我删除最后三个扩展,一切都会起作用,但我不会得到与 BarCode 对象相关的实体。有什么帮助吗?

IQueryable<ScanDocument> result = Context.CreateQuery<ScanDocument>("DocumnetsWithNotRemovedContacts")
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ScanDocumentPropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName + "/" + ContactDocument.BarCodePropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName + "/" + ContactDocument.ContactPropertyName + "/" + Contact.ContactDocumentsPropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName + "/" + ContactDocument.ScanDocumentDetailPropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName + "/" + ContactDocument.ContactPropertyName + "/" + Contact.ContactSourcePropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName + "/" + ContactDocument.ContactPropertyName + "/" + Contact.ElectionDistrictPropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName + "/" + ContactDocument.ContactPropertyName + "/" + Contact.ContactTypePropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName + "/" + ContactDocument.ContactPropertyName + "/" + Contact.ContactSalutationPropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName + "/" + ContactDocument.ContactPropertyName + "/" + Contact.ContactGroupsPropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName + "/" + ContactDocument.ContactPropertyName + "/" + Contact.CategoryInterestsPropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName + "/" + ContactDocument.BarCodePropertyName + "/" + BarCode.ContactDocumentsPropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName + "/" + ContactDocument.BarCodePropertyName + "/" + BarCode.BarCodeActionTypePropertyName)
        .Expand(ScanDocument.ScanDocumentDetailsPropertyName + "/" + ScanDocumentDetail.ContactDocumentsPropertyName + "/" + ContactDocument.BarCodePropertyName + "/" + BarCode.ScanDataTypePropertyName)
        .OrderByDescending(document => document.ID);

在服务器端,我开始使用类似的东西来获取嵌套属性。

CurrentDataSource.ScanDocumentDetails
             .Include(ScanDocumentDetail.ScanDocumentPropertyName)
             .Include(ScanDocumentDetail.ContactDocumentsPropertyName)
             .Include(ScanDocumentDetail.ContactDocumentsPropertyName + "." + ContactDocument.BarCodePropertyName)
             .Include(ScanDocumentDetail.ContactDocumentsPropertyName + "." + ContactDocument.ContactPropertyName + "." + Contact.ContactDocumentsPropertyName)
             .Include(ScanDocumentDetail.ContactDocumentsPropertyName + "." + ContactDocument.ScanDocumentDetailPropertyName)
             .Include(ScanDocumentDetail.ContactDocumentsPropertyName + "." + ContactDocument.ContactPropertyName + "." + Contact.ContactSourcePropertyName)
             .Include(ScanDocumentDetail.ContactDocumentsPropertyName + "." + ContactDocument.ContactPropertyName + "." + Contact.ElectionDistrictPropertyName)
             .Include(ScanDocumentDetail.ContactDocumentsPropertyName + "." + ContactDocument.ContactPropertyName + "." + Contact.ContactTypePropertyName)
             .Include(ScanDocumentDetail.ContactDocumentsPropertyName + "." + ContactDocument.ContactPropertyName + "." + Contact.ContactSalutationPropertyName)
             .Include(ScanDocumentDetail.ContactDocumentsPropertyName + "." + ContactDocument.ContactPropertyName + "." + Contact.ContactGroupsPropertyName)
             .Include(ScanDocumentDetail.ContactDocumentsPropertyName + "." + ContactDocument.ContactPropertyName + "." + Contact.CategoryInterestsPropertyName)
            //.Include(ScanDocumentDetail.ContactDocumentsPropertyName + "." + ContactDocument.BarCodePropertyName + "." + BarCode.ContactDocumentsPropertyName)
            //.Include(ScanDocumentDetail.ContactDocumentsPropertyName + "." + ContactDocument.BarCodePropertyName + "." + BarCode.BarCodeActionTypePropertyName)
            //.Include(ScanDocumentDetail.ContactDocumentsPropertyName + "." + ContactDocument.BarCodePropertyName + "." + BarCode.ScanDataTypePropertyName)
            .Where(c => ids.Contains(c.ScanDocumentID ?? 0)).ToList();

        foreach (var scanDocumentDetail in y)
        {
            foreach (var contactdocuments in scanDocumentDetail.ContactDocuments)
            {
                if (contactdocuments.BarCode != null)
                {
                    int barCodeActionTypeId = contactdocuments.BarCode.BarCodeActionTypeId;
                    contactdocuments.BarCode.BarCodeActionType =
                        CurrentDataSource.BarCodeActionTypes.FirstOrDefault(p => p.ID == barCodeActionTypeId);

                    if (contactdocuments.BarCode.ScanDataTypeID.HasValue)
                    {
                        int scanDataTypeId = contactdocuments.BarCode.ScanDataTypeID.Value;
                        contactdocuments.BarCode.ScanDataType =
                            CurrentDataSource.ScanDataTypes.FirstOrDefault(p => p.ID == scanDataTypeId);
                    }
                }
            }
        }

UPD 异常:“处理响应流时出错。服务器失败并显示以下消息:\r\n处理此请求时出错。” 来源:System.Data.Services.Client 状态码:500

堆栈跟踪:

at System.Data.Services.Client.Xml.XmlAtomErrorReader.Read()
   at System.Xml.XmlSubtreeReader.Read()
   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
   at System.Xml.Linq.XElement.ReadElementFrom(XmlReader r, LoadOptions o)
   at System.Xml.Linq.XElement.Load(XmlReader reader, LoadOptions options)
   at System.Data.Services.Client.AtomParser.XElementBuilderCallback(XmlReader reader)
   at System.Data.Services.Client.AtomParser.ParseCurrentEntry(AtomEntry& targetEntry)
   at System.Data.Services.Client.AtomParser.Read()
   at System.Data.Services.Client.AtomMaterializer.Read()
   at System.Data.Services.Client.MaterializeAtom.MoveNextInternal()
   at System.Data.Services.Client.MaterializeAtom.MoveNext()
   at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at ClientDataServices.MailProcessingManagmentService.GetDocuments(Expression`1 filter) in D:\...\MailProcessingManagmentService.cs:line 41
   at ClientDataServices.MailProcessingManager.GetEntries(Expression`1 predicate) in D:\...\MailProcessingManager.cs:line 24
   at MailProcessingModule.ViewModels.MailProcessingViewModel.RefreshEntityHandler() in D:\...\MailProcessingViewModel.cs:line 113
   at BaseModule.BaseGridViewModel`1.<>c__DisplayClass1a.<ListEntities>b__d(Object e) in D:\...\BaseGridViewModel.cs:line 178
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
4

1 回答 1

0

WCF 数据服务对允许的扩展数量有服务器端限制。我认为它是 14,所以您上面的查询可能会失败。

如果您发布确切的错误消息,则可能有助于确认问题的根本原因。

扩展为 null 的属性应该可以正常工作,不会有任何结果,但这是可以预料的。

于 2012-06-12T19:04:16.910 回答