首页 > 数据库技术 > 详细

Linq to sql 实现多条件的动态查询(方法一)

时间:2015-04-08 12:49:06      阅读:249      评论:0      收藏:0      [点我收藏+]
/// <summary>
/// Linq to sql 多字段动态查询
/// </summary>
/// <returns></returns>
private List<TVacant> ViewBinding(ModelDataContext db,string fyno,string brd,string area,string city,string pos)
{
Expression<Func<TVacant, bool>> expr = n => GetCondition(n,fyno,brd,area,city,pos);
var xQuery = db.TVacant.Where<TVacant>(expr.Compile());
return xQuery.ToList<TVacant>();
}
private bool GetCondition(TVacant tb,string fyno,string brd,string area,string city,string pos)
{
bool boolResult = true;
if (!String.IsNullOrEmpty(fyno))
{
boolResult &= tb.fy_no == fyno;
}
if (!String.IsNullOrEmpty(brd))
{
boolResult &= tb.brd_no == brd;
}
if (!String.IsNullOrEmpty(area))
{
boolResult &= tb.area_no == area;
}
if (!String.IsNullOrEmpty(city))
{
boolResult &= tb.city_no == city;
}
if (!String.IsNullOrEmpty(pos))
{
boolResult &= tb.pos_no == pos;
}
return boolResult;
}

Linq to sql 实现多条件的动态查询(方法一)

原文:http://www.cnblogs.com/json_Chen/p/4401713.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!