I am creating an application section that revolves around pulling transaction information from a database. Due to the nature of the data in the table, there are many columns that I want to filter. I have a filter selection field with 15 fields that I want to create a where clause for the LINQ statement. The interesting part comes up when I want certain fields to be null. For example, I want to be able to filter any or all of them:
- Transaction type
- Response code
- Transaction Amount
- Much more
I can create a predicate that looks like
Func<Transaction, bool> pred = t => t.ResponseCode == ResponseCode && t.TransactionType == TransactionType && t.TransactionAmount > 100.00;
But in order to choose which fields to include in the predicate, I combine the predicates together:
Func<Transaction, bool> pred = t => true;
if(ResponseCode != null)
pred.AndAlso(t => t.ResponseCode == ResponseCode);
And then pass this predicate to the where clause of the LINQ statement.
, , . ?
UPDATE:
. LINQ to SQL, LINQ . Expression?