SelectRepository.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using SnapshotWinFormsApp.Application.Dtos;
  2. using SnapshotWinFormsApp.Repository.Interfaces;
  3. using SqlSugar;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace SnapshotWinFormsApp.Repository;
  11. public class SelectRepository<T> : ISelectRepository<T>
  12. where T : DataTransmission.Entity.Entity, new()
  13. {
  14. private readonly SqlSugarClient _db;
  15. public SelectRepository(CreateInstanceInDto inDto)
  16. {
  17. var context = inDto.DbSqlServer;
  18. _db = context.DbItems.GetValueOrDefault(inDto.Key + "PGSQLDB");
  19. }
  20. public IList<T> GetAll()
  21. {
  22. return _db.Queryable<T>().ToList();
  23. }
  24. public async Task<List<T>> GetAllAsync(CancellationToken token)
  25. {
  26. return await _db.Queryable<T>().ToListAsync(token);
  27. }
  28. public T GetById(string id)
  29. {
  30. return _db.Queryable<T>().Where(m => m.Id == id).First();
  31. }
  32. public ISugarQueryable<T> Queryable()
  33. {
  34. return _db.Queryable<T>();
  35. }
  36. }