linq如何实现动态多条件查询
例如可以按照一个条件查询也可以2个条件 或者3个4个, 是不固定的,表示层调数据访问层的方法求解!...
例如可以按照一个条件查询 也可以2个条件 或者3个 4个, 是不固定的,表示层调数据访问层的方法 求解!
展开
展开全部
我的做法是判断,然后筛选条件
public MyInfoResult GetInfoes(int intPage, int intPageSize, int intFictionID, int intPID, string strKeyword, int intState,
DateTime? dateStart, DateTime? dateEnd, string strOrderby)
{
myInfoResult = new MyInfoResult();
try
{
Fiction myDal = new Fiction(_ConnectionString);
IQueryable<TblSectionInfo> query = myDal.TblSectionInfo;
List<int> infotreeids = new List<int>();
if (intFictionID != -1)
{
query = query.Where(i => i.FkFictionID == intFictionID);
}
if (intPID != -1)
{
query = query.Where(i => i.ParentID == intPID);
}
if (!string.IsNullOrEmpty(strKeyword))
{
query = query.Where(i => i.SectionName.Contains(strKeyword));
}
if (intState != -1)
{
query = query.Where(i => i.State == intState);
}
if (dateStart != null)
{
query = query.Where(i => i.AddDate >= dateStart);
}
if (dateEnd != null)
{
query = query.Where(i => i.AddDate <= dateEnd);
}
query = IQueryable.MyOrderBy(query, strOrderby);
myInfoResult.IsSuc = true;
myInfoResult.Message = query.AsEnumerable().Skip(intPage * intPageSize).Take(intPageSize).ToList();
myInfoResult.MsgCount = query.Count();
}
catch (Exception error)
{
myInfoResult.IsSuc = false;
myInfoResult.Message = error.Message;
}
return myInfoResult;
}
public MyInfoResult GetInfoes(int intPage, int intPageSize, int intFictionID, int intPID, string strKeyword, int intState,
DateTime? dateStart, DateTime? dateEnd, string strOrderby)
{
myInfoResult = new MyInfoResult();
try
{
Fiction myDal = new Fiction(_ConnectionString);
IQueryable<TblSectionInfo> query = myDal.TblSectionInfo;
List<int> infotreeids = new List<int>();
if (intFictionID != -1)
{
query = query.Where(i => i.FkFictionID == intFictionID);
}
if (intPID != -1)
{
query = query.Where(i => i.ParentID == intPID);
}
if (!string.IsNullOrEmpty(strKeyword))
{
query = query.Where(i => i.SectionName.Contains(strKeyword));
}
if (intState != -1)
{
query = query.Where(i => i.State == intState);
}
if (dateStart != null)
{
query = query.Where(i => i.AddDate >= dateStart);
}
if (dateEnd != null)
{
query = query.Where(i => i.AddDate <= dateEnd);
}
query = IQueryable.MyOrderBy(query, strOrderby);
myInfoResult.IsSuc = true;
myInfoResult.Message = query.AsEnumerable().Skip(intPage * intPageSize).Take(intPageSize).ToList();
myInfoResult.MsgCount = query.Count();
}
catch (Exception error)
{
myInfoResult.IsSuc = false;
myInfoResult.Message = error.Message;
}
return myInfoResult;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家提供动态代理服务器服务的企业,旨在帮助用户更好地管理网络访问和安全。以下是一些关于StormProxies的IP动态代理服务的特点:1. 高匿名性:StormProxies的动态代理服务器具有高匿名性,可以有效...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询