.net下MVC中使用Tuple分页查询数据

主要是在DAL层写查询分页的代码。

例如DAL层上代码:

public Tuple<List<WxBindDto>, int> GetMbersInfo(int start, int length, ExtGridSearch condition, Guid sid, Guid accountId, string selbrand)
{
List<WxBindDto> wd = new List<WxBindDto>();
System.Linq.Expressions.Expression<Func<Mall_Shop, bool>> infoWhere = f => f.AccountId == accountId;

if (!string.IsNullOrEmpty(selbrand))
{
infoWhere = infoWhere.And(x => x.BrandIds == selbrand);
}
var vipList = (from lt in base._db.VIPWxBind.Where(v => v.AccountId == accountId && v.SId == sid)
join vi in base._db.VIPInfo.Where(x => x.AccountId == accountId) on lt.MobilePhone equals vi.MobilePhone
join ms in base._db.MallShop.Where(infoWhere) on vi.ShopNO equals ms.ShopNo
select new WxBindDto
{
Id = lt.Id,
}).OrderByDescending(v => v.CreateTime);
int count = vipList.Count();
wd = vipList.Skip(start).Take(length).ToList();
return Tuple.Create(wd, count);
}

在IDAL 、BLL层只需要调用一下就行了,跳过。。。。

最后在Controller层,例如调用代码:

var rst = xxx.xxxx.GetMbersInfo(start, length, condition, sid, accountId, selbrand);

得到的rst就是返回来的结果。

使用rst.Item1得到的是一个查询数据的集合。

使用rst.Item2得到的是一个根据条件查询数据的条数。

即:在DAL层wd、count对应Item1、Item2

 

转载于:https://www.cnblogs.com/LBJLAKERS/p/11301892.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值