简体   繁体   English

为什么LoadProperty没有为1:N关系加载相关实体? (CRM2011,早期绑定实体类)

[英]Why does LoadProperty not load the related entities for 1:N relationships? (CRM2011, early binding entity classes)

Suppose I have a custom entity new_someentity which has 2 other related entities: an "owner" entity which I'll call new_ownerentity (this is a N:1 relationship) and a "child" entity which I'll call new_childentity (1:N relationship). 假设我有一个自定义实体new_someentity ,它有2个其他相关实体:一个“所有者”实体,我称之为new_ownerentity (这是一个N:1的关系)和一个“子”实体,我称之为new_childentity (1:N)关系)。

I'm attempting to populate the related entities by calling LoadProperty : 我试图通过调用LoadProperty来填充相关实体:

new_someentity en = context.new_someentitySet.First();
context.LoadProperty(en, "new_someentity_new_ownerentity");
context.LoadProperty(en, "new_someentity_new_childentity");

Afterward, en.new_someentity_new_ownerentity is populated as I expect it to be with a reference to the owner entity, but en.new_someentity_new_childentity is simply still null. 之后, en.new_someentity_new_ownerentity被填充,因为我期望它与所有者实体的引用,但en.new_someentity_new_childentity仍然是null。 No errors are produced. 没有错误产生。

What's the deal? 这是怎么回事?

On a side note, is there really not a concise way to load a related entity for an IEnumerable of entities without needing to use LoadProperty on each entity individually? 另外,是否真的没有一种简洁的方法来为IEnumerable实体加载相关实体而无需在每个实体上单独使用LoadProperty This seems like a pretty classic case of an N+1 queries issue. 这似乎是N + 1查询问题的一个非常经典的案例。

Just because you think it should return an empty list when the object doesn't have any child entities doesn't mean that's the way LoadProperty works. 只是因为你认为当对象没有任何子实体时它应该返回一个空列表并不意味着LoadProperty的工作方式。

So for anyone else who comes upon this: 所以对于其他人来说:

LoadProperty will leave the property null when there aren't any related records for that record, even on 1:N relationships. 当没有该记录的任何相关记录时,即使在1:N关系上,LoadProperty也会将该属性保留为null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM