高级查找-将相关实体与OR组合 [英] Advanced Find - combine related entitie with OR
问题描述
是否可以创建该查询?
我需要来自地址和联系地址的数据,通常我可以通过 Combine OR $ c组合它们$ c>,但不是这种情况。
我想我必须使用 PreExecute()
方法编写新插件,获取查询,解析数据,然后手动获取相等的地址,或者还有其他方法吗?
我解决了这个问题。 / p>
- 使用
Execute()
方法和一些$ b $创建用于预验证的插件b数据解析方法。 - 在实体视图中,使用
GUID
添加一些字段。 - 如果在您的插件中找到guid视图,它将为您的
实体获取fetchxml查询,而第二个查询实体则将显示默认视图。 - 解析要显示给用户的数据。
- 注册您的插件。
- 利润。
PS我将在重构和获得客户批准后的一两天内添加来源。
编辑:
首先-您需要创建新的 GUID
并添加字符串字段以使用该GUID进行查看(最好将其隐藏给用户)。
使用 RetrieveMultiple
操作和 Post
验证(在 Pre
操作,您可能会丢失所做的更改)
在插件中:主要方法
RetrieveMultiple
将从查询中获取上下文和服务,然后需要获取fetchXml并检查是否有 GUID
。
字符串fetchXml = string.Empty;
var query = context.InputParameters [ Query]作为QueryExpression;
var fetchQuery = context.InputParameters [ Query]为FetchExpression;
if(query == null)
{
if(fetchQuery == null)
{
return;
}
fetchXml = fetchQuery.Query;
}
//将查询转换为获取表达式以进行处理并应用过滤器
else
{
fetchXml =
((QueryExpressionToFetchXmlResponse)
service.Execute(new QueryExpressionToFetchXmlRequest {Query = query}))。FetchXml;
}
if(fetchXml.Contains(OpportunityFilterGuid))
{
ApplyFilter(context,service,query);
}
}
在您的 ApllyFilter中
您需要的方法:
-
从用户那里获取查询(他可以添加一些新文件)。
-
使用
GUID
删除字段。 -
执行查询。
-
删除文件,可能与您的
OR
语句冲突。 -
添加
链接实体
进行查询。 -
执行查询。
-
将第二个查询中收到的实体添加到第一个查询中。
-
不使用不重复的LINQ选择实体。
collectionOne.Entities.GroupBy(oppId => oppId.Id).Select (opp => opp.First())
-
将该数据发送给客户端。
Is there any way to create that query?
I need data from Adress and Contact Adress, normally i can just combine them by Combine OR
but not in this case.
I guess that i must write new plugin with PreExecute()
method, get my query, parse data and then manualy get equal address OR there are other way?
I solved the problem.
- Create Plugin for pre-validation with
Execute()
method and some method for data parsing. - In entity view add some field with
GUID
. - If plugin found guid in your view, it 'll get fetchxml query for your entity and second query entity else 'll show default view.
- Parse data for what you want show for user.
- Register your plugin.
- Profit.
PS I'll add sources in day or two after refactoring and approval from customer.
Edit:
First of all - y need create new GUID
and add string field to view with that guid to view(It is better to hide it from the user).
Create plugin with RetrieveMultiple
action and Post
validation(in Pre
action you may lose your changes)
In plugin: main method
RetrieveMultiple
which will get context and service from wich you will take query, then you need get fetchXml and check if there are your GUID
.
string fetchXml = string.Empty;
var query = context.InputParameters["Query"] as QueryExpression;
var fetchQuery = context.InputParameters["Query"] as FetchExpression;
if (query == null)
{
if (fetchQuery == null)
{
return;
}
fetchXml = fetchQuery.Query;
}
// Convert query to a fetch expression for processing and apply filter
else
{
fetchXml =
((QueryExpressionToFetchXmlResponse)
service.Execute(new QueryExpressionToFetchXmlRequest {Query = query})).FetchXml;
}
if (fetchXml.Contains(OpportunityFilterGuid))
{
ApplyFilter(context, service, query);
}
}
In your ApllyFilter
method you need:
Get query from user(he can add some new fileds).
Delete your field with
GUID
.Execute query.
Delete fileds, that can conflict with your
OR
statement.Add
link-entity
to query.Execute query.
Add received entities from second query to first.
Using LINQ select entities wich are not repeated.
collectionOne.Entities.GroupBy(oppId => oppId.Id).Select(opp => opp.First())
Send that data to client.
这篇关于高级查找-将相关实体与OR组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!