版博士V2.0程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
1.3 KiB

  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Service
  8. {
  9. public class Repository<T> : SimpleClient<T> where T : class, new()
  10. {
  11. public Repository(ISqlSugarClient context = null) : base(context)//注意这里要有默认值等于null
  12. {
  13. if (context == null)
  14. {
  15. base.Context = new SqlSugarClient(new ConnectionConfig()
  16. {
  17. DbType = SqlSugar.DbType.MySql,
  18. //InitKeyType = InitKeyType.Attribute,
  19. IsAutoCloseConnection = true,
  20. ConnectionString = InitDB.ConnectionString
  21. });
  22. base.Context.Aop.OnLogExecuting = (s, p) =>
  23. {
  24. Console.WriteLine(s);
  25. };
  26. }
  27. }
  28. /// <summary>
  29. /// 扩展方法,自带方法不能满足的时候可以添加新方法
  30. /// </summary>
  31. /// <returns></returns>
  32. public List<T> CommQuery(string json)
  33. {
  34. T t = Context.Utilities.DeserializeObject<T>(json);
  35. var list = base.Context.Queryable<T>().WhereClass(t).ToList();
  36. return list;
  37. }
  38. }
  39. }