实体框架LINQ如果语句在where子句中

时间:2018-04-18 07:54:11

标签: c# .net entity-framework linq

我有以下查询:

var filtered = this.context;

if(!string.IsNullOrEmpty(filter1) {
    filtered = filtered.Where(i => i.name == filter1);
}

if(!string.IsNullOrEmpty(filter2) {
    filtered = filtered.Where(i => i.street == filter2);
}

if(!string.IsNullOrEmpty(filter3) {
    filtered = filtered.Where(i => i.nummer == filter3);
}
....

是否可以使用一个具有以下行为的.Where语句来编写它?

filtered = filtered.Where(if(!string.IsNullOrEmpty(filter1) { i.name == filter1})

0 个答案:

没有答案