1.分页
法1:
if (model.PageIndex > 0 && model.PageSize > 0) {
query = query.Limit(model.PageSize * (model.PageIndex - 1), model.PageSize);
}
使用这种分页时,query必须是IQueryProvider类型的,否则编译不通过
法2:
//总条数
var totalCount = query.Count();
// 总页数
var totalPage = totalCount % model.PageSize == 0
? totalCount / model.PageSize
: totalCount / model.PageSize + 1;
if (totalPage >= model.PageIndex)
{
query = query.Skip((model.PageIndex - 1) * model.PageSize).Take(model.PageSize);
}
else
{
return null;
}
这种方式,对query的类型没有那么严格,只要是IEnumerable或List就行
2.InsertBatch
var list=new List();
db.InsertBatch(list);
3.UpdateMany
var list = new[] {1, 2, 3, 4};
db.UpdateMany()
.Where( x => x.UserId.In(list))
.OnlyFields(x => x.Name)
.Execute(new User() {Name = "test"});
3.DeleteMany
var list = new[] {1, 2, 3, 4};
db.DeleteMany()
.Where(x => list.Contains(x.UserId))
.Execute();