我正在尝试弄清楚如何使用多个筛选器查询Salesforce,其中任何一个筛选器都可以为真(类似于传统的WHERE x='' OR y=''
语句)。
下面的代码可以正常工作,但会生成一个'AND‘查询,其中两个筛选器都必须为true:
var dataSource = new GenericSalesforceEntityDataSource("Download__c", GetSalesforceSession);
dataSource.AddDataSourceFilter("Contact__c", new Operator(ComparisonOperator.Equals), profile.ContactId);
dataSource.AddDataSourceFilter("Lead__c", new Operator(ComparisonOperator.Equals), profile.LeadId);
var downloads = dataSource.GetQueryResultsAsEntities();
如果可能,我希望避免将SOQL查询硬编码到我的.NET应用程序中。SOQL是否支持这些类型的查询,或者我是否应该为此使用S4S?
发布于 2012-01-10 19:03:17
SOQL会让这件事变得容易得多,所以这应该是你选择的路线,特别是因为它提供了使用过滤器执行逻辑操作的最简单方法。
发布于 2012-08-15 20:27:18
SOQL具有复合筛选器,这些筛选器允许您以编程方式创建一个DataSource,该查询在where子句中使用OR运算符转换为Sitecore for Salesforce Connector (S4S)查询。
var dataSource = new GenericSalesforceEntityDataSource("Download__c", GetSalesforceSession);
var orFilter = new LogicalDisjunctionFilter();
orFilter.AddDataSourceFilter("Contact__c", ComparisonOperator.Equals, profile.ContactId);
orFilter.AddDataSourceFilter(ApexLog.Fields.Location, ComparisonOperator.Equals, "SystemLog");
// The two filters above will be combined with a logical OR
dataSource.AddDataSourceFilter(orFilter);
var downloads = dataSource.GetQueryResultsAsEntities();
您可以根据需要结合使用LogicalDisjunctionFilter和LogicalConjunctionFilter来构建AND和OR逻辑。
或者,您可以直接将SOQL where子句添加到数据源。
var dataSource = new GenericSalesforceEntityDataSource("Download__c", GetSalesforceSession);
dataSource.SoqlFilter = string.Format("Contact__c = '{0}' OR Location = 'SystemLog'", profile.ContactId);
var downloads = dataSource.GetQueryResultsAsEntities();
或者,正如Matt建议的那样,您可以构建自己的SOQL字符串并直接运行它。
var dataSource = new GenericSalesforceEntityDataSource("Download__c", GetSalesforceSession);
var queryResult = dataSource.RunSoqlQuery(new SoqlQuery(string.Format("Select Id from Download__c where Contact__c = '{0}' OR Location = 'SystemLog'", profile.ContactId)));
var downloads = dataSource.EntitysFromQueryResult<GenericSalesforceEntity>(queryResult);
https://stackoverflow.com/questions/8797248
复制