PostRepository.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. using Masuit.MyBlogs.Core.Infrastructure.Repository.Interface;
  2. using Masuit.MyBlogs.Core.Models.Entity;
  3. using Microsoft.EntityFrameworkCore;
  4. using System;
  5. using System.Linq.Expressions;
  6. using System.Threading.Tasks;
  7. namespace Masuit.MyBlogs.Core.Infrastructure.Repository
  8. {
  9. public partial class PostRepository : BaseRepository<Post>, IPostRepository
  10. {
  11. /// <summary>
  12. /// 添加实体
  13. /// </summary>
  14. /// <param name="t">需要添加的实体</param>
  15. /// <returns>添加成功</returns>
  16. public override Post AddEntity(Post t)
  17. {
  18. DataContext.Add(t);
  19. return t;
  20. }
  21. /// <summary>
  22. /// 获取第一条数据,优先从缓存读取
  23. /// </summary>
  24. /// <param name="where">查询条件</param>
  25. /// <returns>实体</returns>
  26. public override Task<Post> GetAsync(Expression<Func<Post, bool>> @where)
  27. {
  28. return DataContext.Post.Include(p => p.Category).Include(p => p.Seminar).FirstOrDefaultAsync(@where);
  29. }
  30. }
  31. }