I am using PredicateBuilder to generate where clause
var locationFilter = PredicateBuilder.True<dbCompanyLocation>();
locationFilter = locationFilter.And(s => s.IsPrimary == true && s.State == practiceState);
var companyPredicate = PredicateBuilder.True<dbCompany>();
companyPredicate = companyPredicate.And(c => c.dbCompanyLocations.Where(locationFilter));
I am getting following error, Any one can help for this or am i doing something wrong.
Instance argument: cannot convert from 'System.Data.Linq.EntitySet' to 'System.Linq.IQueryable'
The immediate problem seems to be that
dbCompany.dbCompanyLocations
is anEntitySet
, which implementsIEnumerable<T>
rather thanIQueryable<T>
. This means itsWhere
extension method expects aFunc<dbCompanyLocation, bool>
, however thelocationFilter
variable you are providing is anExpression<Func<dbCompanyLocation, bool>>
.You can create a
Func<dbCompanyLocation, bool>
fromlocationFilter
by calling theCompile
method.Another problem however is that even if it did type check,
c => c.dbCompanyLocations.Where(locationFilter)
is not a predicate, sinceWhere
returns anIEnumerable<T>
instead of a bool. You probably meant to useAny
instead ofWhere
i.e.