下面是一个查询:
Contact crmContact = xrm.ContactSet.Where(x => x.ContactId == contactId).SingleOrDefault();我有一个属性,一个EntityReference,如下所示:
crmContact.assigned_clinic;如您所知,EntityReference包含以下属性:
- Id (the Guid of the entity that it refers to)
- LogicalName (what type of entity does this reference references to)
- Name (the 'Name' attribute of the entity that's being refered to)由于某些原因,在某些情况下,LogicalName和Name属性是正确填充的,有时它们是空字符串。
有什么办法强制完全检索这些数据吗?
发布于 2014-09-24 15:19:12
嗯,那没多久。我认为SingleOrDefault()检索了所有内容,但显然,需要调用ToList()才能做到这一点。我将查询更改为:
Contact crmContact = xrm.ContactSet.Where(x => x.ContactId == contactId).ToList().SingleOrDefault();现在,所有EntityReference属性都已正确填充。有时我是这样做的,有时不是,这就解释了“并非总是人烟稠密”的谜团。
发布于 2014-09-24 15:46:10
技术原因写在MSDN上:
EntityReference.Name性质
此属性可以包含值或null。除非从服务器检索到EntityReference对象,否则不会自动填充此属性。
https://stackoverflow.com/questions/26020569
复制相似问题