ef 动态拼接参数查询

可以对ef使用lamda表达式动态添加参数查询:

案例如下:

Func<Std_InspectionContentTableSchema, WhereClip> whereExp = p =>
{
var whereClip = WhereClip.All;
if (DangerLevel != null)
{
whereClip = whereClip && p.DangerLevelStatus == DangerLevel.Value;
}
if (Status != null)
{
whereClip = whereClip && p.Status == Status.Value;
}
return whereClip;
};

 

var list = InspectStandardDB.DBContext.Ji_InspectionContent.Select().Where(m => m.ParentId == search.ParentId).Where(whereExp).ToList();

posted @ 2017-06-16 11:03  飞刀软件  阅读(519)  评论(0编辑  收藏  举报