Skip to content

Add AnyOf to TableQuery to build more complex OR clauses. #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

DouweM
Copy link

@DouweM DouweM commented Apr 15, 2015

We have a filter interface, where our users can specify predicates to filter a large set of data. Some of these predicates should be ANDed, and some of these should be ORed. For AND, predicates can easily be added on top of each other by chaining Where calls, but there's no way to build an OR clause with an a priori unknown number of predicates, since the only way to specify an OR clause is || and SQLite.Net expects a pretty basic expression.

The new AnyOf method takes a (params-)array of predicates, which allows us to make WHERE ... OR ... queries from lists of predicates, like so:

List<Expression<Func<T, bool>>> preds = new List<Expression<Func<T, bool>>>();
// In real life, these would be generated by the filter interface.
preds.Add(thing => thing.Name == "Whatever");
preds.Add(thing => thing.Foo == "Bar");
conn.Table<Thing>.AnyOf(preds.ToArray());

AnyOf looks even nicer like so, although in this case we could also use Where and ||:

conn.Table<Thing>.AnyOf(thing => thing.Name == "Whatever", thing => thing.Foo == "Bar");

Note that this is my first foray into extending SQLite.Net, so cut me a little slack, but feel free to criticize the code to the fullest extent :)

@oysteinkrog
Copy link
Owner

This sounds nice, I'll review/merge when I've got the current prerelease/beta out the door.

@DouweM
Copy link
Author

DouweM commented Apr 18, 2015

@oysteinkrog Thank you. I should add that I haven't been able to test this, as I was unable to get the project to run.

@oysteinkrog
Copy link
Owner

Hmm ok, what is the problem?
Can you compile the two main projects?

@DouweM
Copy link
Author

DouweM commented Apr 18, 2015

@oysteinkrog Never mind, I was able to get it working. Added tests too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants