LINQ 动态查询(多条件)

热恋灬绝情 热恋灬绝情 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
小弟,没有接触过linq,现在项目需要一个linq查询,还有点复杂。求大神指教。
现有一个List<Marker> list 数据源,
Marker 有(id ,type【type1,type2,type3....】,
status【status1,status2,status3.....】 三个属性),

根据List<string> typeList 和List<string> statusList 进行过滤(两个list可能只有一个,可能都存在,所以需要动态查询)。

例如typeList = {type1,type3}; statusList ={status1,status4}

或者 typeList 为空 statusList ={status1}
过滤List<Marker> list 数据源得到 resultList,怎么求得这个resultList。

代码需要这样形式的:
ParameterExpression c = Expression.Parameter(typeof(Customer), "c");  
Expression condition = Expression.Constant(false);
foreach (string s in starts)
{
Expression con = Expression.Call(
Expression.Property(c, typeof(Customer).GetProperty("CustomerID")),
typeof(string).GetMethod("StartsWith",
new Type[] { typeof(string) }),
Expression.Constant(s));
condition = Expression.Or(con, condition);
}
Expressionbool>> end =
Expression.Lambdabool>>
(condition, new ParameterExpression[] { c });
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
热恋灬绝情
LINQ 8,492 成员 4,736 内容