采取以下措施。
var query = context.Fields
.Where(
x => x.DeletedAt == null
);
// Apply search
if( searchCriteria != null )
{
if( searchCriteria.SearchTerm != "" )
{
query.Where(
x => x.Location.Contains( searchCriteria.SearchTerm )
);
}
}
这不会起作用,因为有两个where语句,他们没有加入。
我该怎么做?它可能看起来像这样:
var query = context.Fields
.Where(
x => x.DeletedAt == null &&
{
if( searchCriteria != null )
{
if( searchCriteria.SearchTerm != "" )
{
return x.Location.Contains( searchCriteria.SearchTerm );
}
}
}
);
答案 0 :(得分:2)
以下内容有什么问题:
var query = context.Fields
.Where(
x => x.DeletedAt == null
);
// Apply search
if( searchCriteria != null )
{
if( searchCriteria.SearchTerm != "" )
{
query = query.Where(
x => x.Location.Contains( searchCriteria.SearchTerm )
);
}
}
return query;