I am using Entity framework 4 and I have the following piece of code:
public decimal GetSchoolSuccessRate(EvaluationComparationFilter filter)
{
return this.GetSuccessRate(x => x.TestCampaignId == filter.TestCampaignId &&
x.SubjectId == filter.SubjectId &&
x.SectionNo == 0, filter.CountSvp);
}
private decimal GetSuccessRate(Func<FinalResult_Base, bool> wherePredicate, bool countSvp)
{
using (var db = new DataEntities())
{
IQueryable<FinalResult_Base> query = db
.FinalResult_Bases.Where(wherePredicate).AsQueryable();
if (!countSvp)
query = query.Where(x => x.SpecialNeeds == 0);
query.Any(); //--HERE is created the SELECT with NO WHERE clause
....
}
}
I don't understand why the resulting SELECT
statmenet at line query.Any()
does not have any WHERE
clause. Neither filter from wherePredicate
nor x.SpecialNeeds == 0
is applied.
Any idea?
UPDATE 1:
The problem seems to be the wherePredicate
, which is of type Func not Expression. I will try to use Expression.