Dynamic "OR" linq predicate for querying the database.

Topics: Troubleshooting, Writing modules
Mar 9, 2012 at 1:33 PM
Edited Mar 9, 2012 at 1:48 PM

So I'm trying to query the RoutePartRecord table based on the ids in my IEnumerable<ContentItemRecord> based on the id's found on each contentitemrecord. So I thought this would be a good time to make a dynamic OR linq query using the predicate builder helper class. What I want to know is am I doing this the best way or is there a more efficient way to do this.


This is inside my service class for my module.



public IEnumerable<RoutePart> GetRouteData(IEnumerable<ContentItemRecord> contentItemRecords)

            var predicate = PredicateBuilder.False<RoutePartRecord>();

            foreach (var record in contentItemRecords)
                var tmp = record;
                predicate = predicate.Or(t => t.ContentItemRecord.Id == tmp.Id); //<---is this in itself doing a foreach as well?
            return _contentManager