码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2015-04-08 12:49:35      阅读:162      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!