问题描述
我经常使用 QueryExpression ,但到目前为止,这是直接从中获取或输入的。最近,我得知有一个叫做 LinkedEntity 的东西,我开始寻找它。作为示例,我受到了一个关于SO的相关问题的启发,并开始创建一个表达式,以获取列表的所有成员。
I'm using QueryExpression often but this far, it's been a straigh-forward get-this-from-that or put-this-in-that. Recently, I learned that there's something called LinkedEntity and I started looking for it. As an example I got inspired by a related question here on SO and I started to create an expression for getting all the members of a list given it's guid.
所有示例我发现遵循相同的模式-与说明。来自,我ve知道这是一种过时的方法(CRM 4.0)。我未能找到一个最新的示例,而且不确定如何设计链接。
All the examples I've found follow the same pattern, though - as this example illustrates. From this question, I've learned that it's an obsolete approach (CRM 4.0). I've failed founding a more up-to-date example and I'm not sure how to design the linkage.
有人在乎提供示例代码吗?
Anybody cares to provide a sample code?
Guid guid = ...;
QueryExpression request = new QueryExpression
{
EntityName = "account",
ColumnSet = new ColumnSet(true),
LinkEntities= ???, // How to link the entities correctly?
Criteria = new FilterExpression { ??? } // How to filter for *guid* only?
};
我创建了一个fetch-XML来链接两个实体,但是不清楚如何翻译将其发送到 QueryExpression 实体。我有这样的东西。有任何建议吗?
I've created a fetch-XML linking two entities but I'm not clear on how to translate it to QueryExpression entity. I've got something like this. Any suggestions?
LinkEntity linkListToMember = new LinkEntity(
"list", "listmember", "listid", "listid", JoinOperator.Natural);
LinkEntity linkMemberToContact = new LinkEntity(
"listmember", "account", "entityid", "accountid", JoinOperator.Natural);
推荐答案
链接实体充当您的SQL Join。将构造函数与from和to实体以及属性名称一起使用
A Link Entity serves as your SQL Join. Use the Constructor with the from and to entity and attribute names
public LinkEntity(
string linkFromEntityName, // This is the Entity Logical Name of your Query Expression, or parent LinkEntity
string linkToEntityName, // This is the Entity Logical Name of the entity you'd like to link to
string linkFromAttributeName, // This is the attribute name on your from entity, containing your join key
string linkToAttributeName, // This is the attribute name on your to entity, containing your join key
JoinOperator joinOperator) // This is the type of Join you'd like to perform
使用链接实体,您可以添加链接条件过滤返回的结果。您还可以添加列并从相关实体返回数据。
Using the Link Entity, you can add Link Criteria to filter the results returned. You can also add Columns and return data from related entities.
如果Konrad列出的52行代码看起来太冗长,使用定义在。
If the 52 lines of code that Konrad lists seems too verbose, this will do the same exact thing, in 15 lines, using the extension methods defined here.
Guid guid = ...;
IOrganizationService service;
QueryExpression request = new QueryExpression("account")
{
ColumnSet = new ColumnSet("name", "region"),
};
request.Criteria.AddCondition("name", ConditionOperator.NotNull);
request.Criteria.AddCondition("region", ConditionOperator.NotNull);
var listLink = request.AddLink("listmember", "accountid", "entityid").
AddChildLink("list", "listid");
listLink.Columns.AddColumn("listname");
listLink.LinkCriteria.AddCondition("listid", ConditionOperator.Equal, guid);
这篇关于如何使用QueryExpression对象获取营销列表的成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!