本文整理汇总了C#中FilterExpression.AddFilter方法的典型用法代码示例。如果您正苦于以下问题:C# FilterExpression.AddFilter方法的具体用法?C# FilterExpression.AddFilter怎么用?C# FilterExpression.AddFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilterExpression
的用法示例。
在下文中一共展示了FilterExpression.AddFilter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Experiment_For_Filter_Groups
public void Experiment_For_Filter_Groups()
{
// var sql = string.Format("Select C.firstname, C.lastname From contact Where firstname Like '%ax%' ");
var connectionString = ConfigurationManager.ConnectionStrings["CrmOrganisation"];
var serviceProvider = new CrmServiceProvider(new ExplicitConnectionStringProviderWithFallbackToConfig() { OrganisationServiceConnectionString = connectionString.ConnectionString },
new CrmClientCredentialsProvider());
var orgService = serviceProvider.GetOrganisationService();
using (orgService as IDisposable)
{
// var request = new RetrieveMultipleRequest();
var query = new QueryExpression("contact");
// request.Query = query;
query.ColumnSet.AddColumn("firstname");
query.ColumnSet.AddColumn("lastname");
var condition1 = new ConditionExpression("firstname", ConditionOperator.Equal, "Max");
var condition2 = new ConditionExpression("lastname", ConditionOperator.Equal, "Planck");
var filter1 = new FilterExpression(LogicalOperator.And);
filter1.AddCondition(condition1);
filter1.AddCondition(condition2);
var condition3 = new ConditionExpression("firstname", ConditionOperator.Equal, "Albert");
var filter2 = new FilterExpression(LogicalOperator.Or);
filter2.AddCondition(condition3);
filter2.AddFilter(filter1);
query.Criteria.Filters.Clear();
query.Criteria.AddFilter(filter2);
var results = orgService.RetrieveMultiple(query);
int resultCount = 0;
foreach (var r in results.Entities)
{
resultCount++;
Console.WriteLine(string.Format("{0} {1}", (string)r["firstname"], (string)r["lastname"]));
}
Console.WriteLine("There were " + resultCount + " results..");
}
}
示例2: ToFilterExpression
public static FilterExpression ToFilterExpression(this XElement elem, XrmFakedContext ctx)
{
var filterExpression = new FilterExpression();
filterExpression.FilterOperator = elem.GetAttribute("type").Value.Equals("and") ?
LogicalOperator.And : LogicalOperator.Or;
//Process other filters recursively
var otherFilters = elem
.Elements() //child nodes of this filter
.Where(el => el.Name.LocalName.Equals("filter"))
.Select(el => el.ToFilterExpression(ctx))
.ToList();
//Process conditions
var conditions = elem
.Elements() //child nodes of this filter
.Where(el => el.Name.LocalName.Equals("condition"))
.Select(el => el.ToConditionExpression(ctx))
.ToList();
foreach (var c in conditions)
filterExpression.AddCondition(c);
foreach (var f in otherFilters)
filterExpression.AddFilter(f);
return filterExpression;
}