MSCRM中如何用OData和Web API实现多字段匹配值查询记录?
Absolutely, you can pull this off with OData—let me walk you through how!
First, let's clear up a possible misunderstanding: the standard OData $filter syntax does support using the or operator across different fields. The restriction you read about likely applies to a specific edge case (like applying multiple filters to the same field in a narrow context) or might be specific to a particular OData service implementation, not the core OData specification.
The straightforward solution
For your exact requirement, you can directly chain or conditions across the three telephone fields in your $filter clause:
/Accounts?$filter=telephone1 eq '555 555 555' or telephone2 eq '555 555 555' or telephone3 eq '555 555 555'
This will return all Account records where any of the three telephone fields matches your target number exactly.
Fallback for restricted OData services
If you're working with an OData service that does enforce an unusual restriction on cross-field or operators (rare, but possible in some legacy or custom setups), you can use a workaround with string concatenation and the contains function:
/Accounts?$filter=contains(concat(concat(telephone1, '|'), concat(telephone2, '|'), telephone3), '555 555 555')
We add a separator like | between fields to avoid false matches (e.g., preventing a partial match that spans the end of one field and the start of another). This checks if your target number exists anywhere in the combined string of all three telephone fields.
Either approach should get you the results you need!
内容的提问来源于stack exchange,提问作者Nicolas

