革博士V2程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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