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();