FreeSqlRepositoryExtensions.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Admin.Core.Repository;
  2. using System;
  3. using System.Linq.Expressions;
  4. public static class FreeSqlDbContextExtensions
  5. {
  6. /// <summary>
  7. /// 返回默认仓库类
  8. /// </summary>
  9. /// <typeparam name="TEntity"></typeparam>
  10. /// <typeparam name="TKey"></typeparam>
  11. /// <param name="that"></param>
  12. /// <param name="filter">数据过滤 + 验证</param>
  13. /// <returns></returns>
  14. public static IRepositoryBase<TEntity, TKey> GetRepositoryBase<TEntity, TKey>(this IFreeSql that, Expression<Func<TEntity, bool>> filter = null) where TEntity : class, new()
  15. {
  16. return new DefaultRepositoryBase<TEntity, TKey>(that, filter);
  17. }
  18. /// <summary>
  19. /// 返回默认仓库类,适用联合主键的仓储类
  20. /// </summary>
  21. /// <typeparam name="TEntity"></typeparam>
  22. /// <param name="that"></param>
  23. /// <param name="filter">数据过滤 + 验证</param>
  24. /// <returns></returns>
  25. public static IRepositoryBase<TEntity, long> GetRepositoryBase<TEntity>(this IFreeSql that, Expression<Func<TEntity, bool>> filter = null) where TEntity : class, new()
  26. {
  27. return new DefaultRepositoryBase<TEntity, long>(that, filter);
  28. }
  29. public static IRepositoryBase<TEntity, long> GetRepositoryBase<TEntity>(this IFreeSql that, MyUnitOfWorkManager muowManger) where TEntity : class, new()
  30. {
  31. return new DefaultRepositoryBase<TEntity, long>(that, muowManger);
  32. }
  33. }