ef动态拼接查询字段

ef动态拼接查询字段可以使用委托的方式Func

Func<Sc_V_PersonalInspectionTableSchema, WhereClip> whereExp = p =>
{
var whereClip = WhereClip.All;
if (PlanBeginTime!=null)
{
whereClip = whereClip && p.PlanBeginTime == PlanBeginTime;
}
if (PlanEndTime!=null)
{
whereClip = whereClip && p.PlanEndTime == PlanEndTime;
}
if (!string.IsNullOrEmpty(ProjectName))
{
whereClip = whereClip && p.GroupName.Contains(ProjectName);
}
return whereClip;
};

var list = DataAccess.LepulsDB.DBContext.Sc_V_PersonalInspection.Select().Where(whereExp).ToList();

 

posted @ 2016-12-14 14:37  飞刀软件  阅读(427)  评论(0)    收藏  举报