当我将BarCodeId FK更改为允许在ContactDocument中使用null时。之后,如果ContactDocument中的任何实体具有null 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()
答案 0 :(得分:0)
WCF数据服务对允许的扩展数量有服务器端限制。我认为它是14,所以你上面的查询可能会失败。
如果您要发布确切的错误消息,则可能有助于确认问题的根本原因。
扩展null属性应该可以正常工作,不会有任何结果,但这是预期的。