I have an ASPX page that collects 5 optional search criteria from a user and returns the result in a grid. Once the criteria are collected and the view button clicked, the code behind generates the filter like we have below
// aSearchCriteria is a class that holds the criteria
...
string filter = string.Empty;
if (!string.IsNullOrEmpty(aSearchCriteria.RegistrationNumber)) filter =
"f.BusinessRegistrationNumber = " +
aSearchCriteria.BusinessRegistrationNumber + " ";
if (aSearchCriteria.ChangedStartDate != null && aSearchCriteria.ChangedEndDate != null)
{
if (!string.IsNullOrEmpty(filter))
{
filter += " && f.ChangedDate >= " +
aSearchCriteria.ChangedStartDate.ToShortDateString() +
" && f.ChangedDate <= " +
aSearchCriteria.ChangedEndDate.ToShortDateString() + " ";
}
else
{
...
}
}
...
Using (CustomerEntities db = new CustomerEntities())
{
if (!string.IsNullOrEmpty(filter))
{
filter = "f => " + filter;
**return db.Customers.Where(filter).ToList();**
}
else
...
}
...
Sample:
"filter" value: f => f.ChangedDate > 01/01/2012 && f.ChangedDate < 14/01/2012
我执行这一错误信息:
问题不成立。 近期;第6行,第5栏。