I'm trying to create a Linq statement that queries both columns that exist on my entity as properties and those that don't but exist as columns in the database for the entity.
For example, I have a collection of Book entities. Each Book has an ID and Title property and a matching column in the database. But, lets say the table for Book also contains a column field for Author and my Book entity doesn't have this.
A normal query involving the ID and the Title might look like this:
Books.Where(b=>b.ID == 123 && b.Title == "Title")
But, I want to also dynamically add the equivalent of " AND Author = 'Name' " to the above query as well. The Author property doesn't exist on the Book object.
The extra fields and the values they should contain will actually be available in a Dictionary. So I will need to dynamically add multiple AND [FieldName] = '[Value]' conditions to the query.
It might help explain why I would need this to know that I'm using Azure Table Storage and I have overridden the serialize that turns a Book entity into the XML stored in Azure.
Edit -
I've tried using the Dynamic Linq library but it does not work.
Books.Where(b=>b.ID == 123 && b.Title == "Title").Where("Author = @0", "SomeName").ToList();
Throws: System.Linq.Dynamic.ParseException: No property or field 'Author' exists in type 'Book'.
Also,
I know using Books.AddQueryOption("$filter","Author eq 'SomeName'") works when used by itself. But I have no idea how to use AddQueryOption along with an existing Where statement.