0

I am trying to build up a predicate which will filter my data. I have a List<int> and I need get all data where the ID matches the data in the list. Can I do this?

Currently I have it working like so:

Expression<Func<MonthlyDebitingReportItem, bool>> predicate = PredicateBuilder.True<MonthlyDebitingReportItem>();

foreach (int item in monthlyDebitingFilter.WrittenOffIDs) {
                predicate = predicate.Expand().And(r => r.WrittenOffID == item);
            }

I would like to have fluid LINQ which would basically create LINQ like so:

Where ListOfIDs.Contains(ID)
Andrew Kilburn
  • 2,251
  • 6
  • 33
  • 65
  • 2
    why not do it the normal way ListOfIDs.Where(x=>somelistofIds.Contains(x)) ? – Seabizkit May 06 '16 at 13:42
  • Because I am using a predicate builder to build up a dynamic LINQ statement and I would like to sue intellisense – Andrew Kilburn May 06 '16 at 13:57
  • 1
    I have no problem with that, but maybe you should make that clear in your question.... as you say you want to filter on Id, then there is no need to do it with PredicateBuilder. Just pass two lists to a function that filters out the remainder, i suspect that you may have a greater requirement, but its not clear from the question. Seems odd to create something which is already built in, if not then you are not expressing your usage correctly. I'm merely pointing out that there is something built in to do what you are asking... so why not use that.your requirement will be met with it. – Seabizkit May 06 '16 at 14:07

0 Answers0