革博士程序V1仓库
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

44 行
1.5 KiB

  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. }