Repository.cs 744 B

1234567891011121314151617181920212223242526272829303132333435
  1. using SnapshotWinFormsApp.Repository.Interfaces;
  2. using SqlSugar;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace SnapshotWinFormsApp.Repository;
  9. public class Repository<T> : IRepository<T> where T : class, new()
  10. {
  11. private readonly SqlSugarClient _db;
  12. public Repository(DbSqlServer context, string key)
  13. {
  14. _db = context.DbItems.GetValueOrDefault(key+ "SQLServerDB");
  15. }
  16. public T GetById(int id)
  17. {
  18. return _db.Queryable<T>().InSingle(id);
  19. }
  20. public List<T> GetAll()
  21. {
  22. return _db.Queryable<T>().ToList();
  23. }
  24. public ISugarQueryable<T> Queryable()
  25. {
  26. return _db.Queryable<T>();
  27. }
  28. }