Tuesday, September 20, 2011

filter a collection with a bag of ids

Use LinqSpecs to match a collection against a collection of ids like so:

public static Specification<Foo> IdCriteria(IList<Guid> Ids)

{

   var fooSpec = new AdHocSpecification<Foo>(f => Ids.Contains(f.Id));

   return fooSpec;

}

   

Call the method like so:

specBuilder.AddAnd(GetSpecs.IdCriteria((Array.ConvertAll(myListOfIdsAsStrings, e => new Guid(e)))));

No comments:

Post a Comment