I use linqToEntities
and would like to add OR
condition dynamically.
I know that there is a great library PredicateBuilder
by brother Albahari and it can solve my task, but I cannot use it.
My conditions looks like this:
IEnumerable<Condition> conditions = new List<Condition>()
{
new Condition(){IdReference = 1, TableName = "Table1" },
new Condition(){IdReference = 2, TableName = "Table2" },
new Condition(){IdReference = 3, TableName = "Table3" },
// and so on
};
What I have is:
var histories = db.History as IQueryable<History>;
foreach (var cond in conditions)
{
//What code should be here to be translated into:
/*
histories = histories
.Where(h => h.IdReference == 1 && h.TableName =="Table1"
|| h.IdReference == 2 && h.TableName == "Table2"
|| h.IdReference == 3 && h.TableName == "Table3");
// and so on
*/
}
However, I do not know in advance how many conditions
would be.
How is it possible to add OR
conditions dynamically from IEnumerable<Condition>
?