使用“实体引用”类型过滤实体? [英] Filtering Entities with type Entity Reference?

查看:83
本文介绍了使用“实体引用”类型过滤实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用实体引用对象的字符串值进行查询?

How do I query using the string value for an entity reference object?

QueryExpression query = new QueryExpression("entityName");
query.Criteria = new FilterExpression();
query.Criteria.AddCondition("parentaccountid", ConditionOperator.Like, "14%");

此处的 parentaccountid基本上是实体引用类型。

"parentaccountid" here is basically of type entityreference.

EntityCollection results = crmService.RetrieveMultiple(query);

当我尝试获取结果时,收到无法转换&的错误。

When I try to get the results I receive the error unable to cast & it is expecting GUID.

我知道这不可能,但我仍然错了。
是否有其他替代方法使用字符串作为实体引用对象进行查询?

I know that this might not be possible but still I may be wrong. Is there any alternate way to query using string for entity reference object?

附加信息:

有一个实体机会,它具有名称,名称,订单金额,父母身份等几个属性。

There is an entity "Opportunity", it has several attributes with names name,orderamount,parentaccountid etc.

在应用过滤器后,我按如下所示调用服务:

I'm calling service as below after applying filters:

QueryExpression query = new QueryExpression("opportunity");
query.Criteria = new FilterExpression();
query.Criteria.AddCondition("name", ConditionOperator.Like, "14%");
FilterExpression childFilter = query.Criteria.AddFilter(LogicalOperator.Or);
childFilter.AddCondition("tmeic_proposalnumber", ConditionOperator.Equal, "XXXXXX");
EntityCollection results = crmService.RetrieveMultiple(query);

我分配的结果如下:

DataTable dt = new DataTable();
dt.Columns.Add("CustomerName");
try
{
    foreach (Entity item in results.Entities)
    {
        DataRow dr = dt.NewRow();
        dr["CustomerName"] = item.Contains("parentaccountid") ? item.GetAttributeValue<EntityReference>("parentaccountid").Name : string.Empty;
        dt.Rows.Add(dr);
    }
}

我将此数据表绑定到Windows中的datagridview表单应用程序:

I'm binding this data table to datagridview in windows forms app:

dgv.DataSource=dt;

现在,我要使用客户名称进行搜索。

Now, I want to search using the customer name.

但是当我在下面添加过滤器时,它会因为期望GUID而引发错误。

But when I add the filter as below it throws error because it is expecting GUID.

query.Criteria.AddCondition("parentaccountid", ConditionOperator.Like, "14%");

我为客户名称分配了 GetAttributeValue( parentaccountid)。Name 。我的搜索参数仅是名称,因为我正在datagridview中显示名称,而不是GUID。

I assigned GetAttributeValue("parentaccountid").Name for customer name. My search parameter is name only as I'm displaying name in the datagridview instead of GUIDs.

但是在QueryExpression中,它要求提供GUID。我该如何实现?

But in the QueryExpression it asks for GUIDs. How do I achieve this?

您可以通过添加类型为EntityReferences&的过滤器来提供我们查询的任何链接吗?结果是从datagridview绑定的吗?

Can you provide any link where we query by adding filters with types EntityReferences & the result is binded from datagridview?

推荐答案

您需要过滤名称 account 实体的c>属性。

You need to filter on the name attribute of the associated account entity.

加入 account 实体添加到机会实体,并向其应用 ConditionExpression ,如下所示:

Join the account entity to the opportunity entity and apply a ConditionExpression to it like this:

var query = new QueryExpression("opportunity");
LinkEntity link = query.AddLink("account", "parentaccountid", "accountid");
link.AddCondition("name", ConditionOperator.BeginsWith, "14");

这篇关于使用“实体引用”类型过滤实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆