using EFCoreSecondLevelCacheInterceptor; using Masuit.MyBlogs.Core.Infrastructure.Repository.Interface; using Masuit.MyBlogs.Core.Models.Entity; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using Z.EntityFramework.Plus; namespace Masuit.MyBlogs.Core.Infrastructure.Repository { public partial class MenuRepository : BaseRepository, IMenuRepository { /// /// 添加实体 /// /// 需要添加的实体 /// 添加成功 public override Menu AddEntity(Menu t) { DataContext.Add(t); return t; } /// /// 基本查询方法,获取一个集合 /// /// 排序 /// 查询条件 /// 排序字段 /// 是否升序 /// 还未执行的SQL语句 public override IOrderedQueryable GetQuery(Expression> @where, Expression> @orderby, bool isAsc = true) { return isAsc ? DataContext.Menu.Include(m => m.Children).ThenInclude(m => m.Children).ThenInclude(m => m.Children).Where(where).OrderBy(orderby) : DataContext.Menu.Include(m => m.Children).ThenInclude(m => m.Children).ThenInclude(m => m.Children).Where(where).OrderByDescending(orderby); } /// /// 基本查询方法,获取一个集合,优先从二级缓存读取 /// /// 查询条件 /// 还未执行的SQL语句 public override List GetQueryFromCache(Expression> @where) { return DataContext.Menu.Include(m => m.Children).ThenInclude(m => m.Children).ThenInclude(m => m.Children).Where(where).Cacheable().ToList(); } } }