我正在使用 IQueryable 来构建我的查询。
IQueryable<PropertyPosts> posts = context.PropertyPosts;
Run Code Online (Sandbox Code Playgroud)
之后,基于几个条件,我将Where子句附加到我的查询中,
if (item.ApartmentCondo == 1)
{
posts= posts.Where(x => x.name == item.name &&
x.PropertyType == PropertyType.ApartmentCondo );
}
if (item.House == 1)
{
posts= posts.Where(x => x.name == item.name &&
x.PropertyType == PropertyType.House );
}
Run Code Online (Sandbox Code Playgroud)
注意:还有其他几个 where 条件。
之后,当我执行以下查询时,
List<PropertyPosts> posts2 = posts.ToList();
Run Code Online (Sandbox Code Playgroud)
上述所有的地方条件将是“AND后。
但相反,我需要将 Where 条件进行“或”运算。
这意味着我需要一种方法来附加几个 Where 条件,但所有这些条件都应该在它们之间执行“OR”条件。
我怎样才能做到这一点?有没有替代方法而不是使用“ Where ”?