XeroAPI.Net icon indicating copy to clipboard operation
XeroAPI.Net copied to clipboard

Filter using more than one condition

Open dkotov opened this issue 12 years ago • 2 comments

So I'm trying to do next:

repository.Contacts
    .Where(c => c.ContactNumber == "Foo" || c.Name == "Bar")
    .ToList();

and when I check results I see that only one of these conditions was applied (right or left depending on what logical operator was used -- AND or OR). At the same time when I try to do this filtering using API Preview it works fine: ContactNumber = "Foo" OR Name = "Bar"

Am I doing anything wrong?

dkotov avatar Apr 08 '13 20:04 dkotov

The c.ContactNumber == "Foo" is being parsed out of the WHERE filter and added as an id to the url path. The whole url would look something like this:

https://api.xero.com/api.xro/2.0/Contacts/Foo?WHERE=Name%3D%3DBar

The contact number property on each contact is considered a unique identifier. It makes the lookup in our database very fast when added to the url path, as opposed to the generic ?WHERE= filter, which is typically slower.

There's currently no way to force the XeroAPI.Net library to generate a ContactNumber = "Foo" OR Name = "Bar" WHERE querystring parameter.

Dan..

danbarratt avatar Apr 08 '13 22:04 danbarratt

@danbarratt, thank you for your quick answer. I see that API Preview allows retrieving Contact by ContactNumber in the same way as by ID too and I understand all the advantages of this approach. But API Preview doesn't deny filtering by these fields, so why XeroAPI.Net library behave differently? Let me explain an issue that I have because of this optimization: I'm trying to retrieve batch of contacts by ContactNumber and currently I have to get each of them individually (which looks inefficiently and may lead to API limits exceeding) or get all of them each time (even with some filtering it's better but not good enough) or store them locally (which add complexity to my system). So having an ability to choose between speed and functionality would be great for me and maybe for other developers.

UPD: I found workaround for my particular case.

dkotov avatar Apr 09 '13 07:04 dkotov