Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to use the PredicateBuilder, as described here - http://www.albahari.com/nutshell/predicatebuilder.aspx

The following code

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

        predicate = predicate.Or(p => p.Locality.Contains(criteria.Locality));
        predicate = predicate.Or(p => p.Name.Contains(criteria.Name));
        predicate = predicate.Or(p => p.Town.Contains(criteria.Town));

        List<StreetDTO> streetData = StreetData.Instance();

        var streetList = from street in streetData.Where(predicate)
                         select street;

as far as I see this should work, according to the example

var newKids  = Product.ContainsInDescription ("BlackBerry", "iPhone");

var classics = Product.ContainsInDescription ("Nokia", "Ericsson")
                      .And (Product.IsSelling());
var query =
  from p in Data.Products.Where (newKids.Or (classics))
  select p;

but all I get is

Error 1 The type arguments for method 'System.Linq.Enumerable.Where(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

I'm trying to gain some understanding in LINQ 'on-the-job', so apologies if this is a simple question.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
869 views
Welcome To Ask or Share your Answers For Others

1 Answer

Ah; your list is using IEnumerable<T> extension methods (rather than IQueryable<T>) - try:

var streetList = from street in streetData.AsQueryable().Where(predicate)
                 select street;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...