RolePermission.Dal/BaseRepository.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using RolePermission.IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using RolePermission.Model.SearchParam;
namespace RolePermission.DAL
{
public class BaseRepository<T> : IBaseRepository<T> where T : class,new()
{
/// <summary>
/// EF上下文对象
/// </summary>
private readonly DbContext Db;
public BaseRepository(DbContext dbContext)
{
Db = dbContext;
}
/// <summary>
/// 查询
/// </summary>
/// <param name="whereLambda"></param>
/// <returns></returns>
public IQueryable<T> LoadEntities(Expression<Func<T, bool>> whereLambda)
{
return Db.Set<T>().Where<T>(whereLambda);
}
/// <summary>
/// 查询所有
/// </summary>
/// <param name="entity">需要包含的实体</param>
/// <returns></returns>
public IQueryable<T> LoadEntitiesAll(string entity)
{
return string.IsNullOrEmpty(entity)?Db.Set<T>().AsQueryable():Db.Set<T>().Include(entity).AsQueryable();
}
/// <summary>
/// 实现对数据的分页查询
/// </summary>
/// <typeparam name="model">实体对象</typeparam>
/// <param name="pageIdex">页码</param>
/// <param name="pageSize">每页显示记录数</param>
/// <param name="toalCount">总记录数</param>
/// <param name="whereLambda">条件表达式</param>
/// <param name="orderby">排序字段</param>
/// <param name="isAsc">是否升序(true:表示升序, false:降序)</param>
/// <returns></returns>
public IQueryable<T> LoadPageEntities<model>(int pageIdex, int pageSize, out int toalCount, Expression<Func<T, bool>> whereLambda, string orderby, bool ? isAsc)
{
var temp = Db.Set<T>().Where<T>(whereLambda.Compile()).AsQueryable(); //Compile()
toalCount = temp.Count();
if (isAsc.HasValue)//排序
{
temp = isAsc.Value ? temp.OrderBy<T>(orderby).Skip<T>((pageIdex - 1) * pageSize).Take<T>(pageSize) : temp = temp.OrderByDescending<T>(orderby).Skip<T>((pageIdex - 1) * pageSize).Take<T>(pageSize); ;
}
else
后面还有 38 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。