SubTools.cs 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. namespace SqlSugar
  7. {
  8. public class SubTools
  9. {
  10. public static List<ISubOperation> SubItems(ExpressionContext Context)
  11. {
  12. return new List<ISubOperation>()
  13. {
  14. new SubSelect() { Context=Context },
  15. new SubWhere(){ Context=Context },
  16. new SubWhereIF(){ Context=Context },
  17. new SubLeftJoin(){ Context=Context },
  18. new SubInnerJoin(){ Context=Context },
  19. new SubAnd(){ Context=Context },
  20. new SubAndIF(){ Context=Context },
  21. new SubAny(){ Context=Context },
  22. new SubNotAny(){ Context=Context },
  23. new SubBegin(){ Context=Context },
  24. new SubFromTable(){ Context=Context },
  25. new SubCount(){ Context=Context },
  26. new SubMax(){ Context=Context },
  27. new SubMin(){ Context=Context },
  28. new SubSum(){ Context=Context },
  29. new SubAvg(){ Context=Context },
  30. new SubOrderBy(){ Context=Context },
  31. new SubOrderByDesc(){ Context=Context },
  32. new SubGroupBy(){ Context=Context},
  33. new SubAs(){Context=Context},
  34. new SubHaving(){ Context=Context},
  35. new SubWithNolock(){ Context=Context },
  36. new SubEnableTableFilter(){ Context=Context },
  37. new SubSelectStringJoin{ Context=Context },
  38. new SubDistinctCount{ Context=Context },
  39. new SubToList{ Context=Context},
  40. new SubFirst(){ Context=Context },
  41. new SubAsWithAttr(){ Context=Context }
  42. };
  43. }
  44. public static string GetSubReplace(ExpressionContext context)
  45. {
  46. if (context.SubQueryIndex == 0)
  47. return string.Empty;
  48. else
  49. return "subTableIndex"+context.SubQueryIndex+".";
  50. }
  51. public static List<ISubOperation> SubItemsConst = SubItems(null);
  52. public static string GetMethodValue(ExpressionContext context, Expression item, ResolveExpressType type)
  53. {
  54. var newContext = context.GetCopyContext();
  55. newContext.MappingColumns = context.MappingColumns;
  56. newContext.MappingTables = context.MappingTables;
  57. newContext.InitMappingInfo = context.InitMappingInfo;
  58. newContext.RefreshMapping = context.RefreshMapping;
  59. newContext.IgnoreComumnList = context.IgnoreComumnList;
  60. newContext.SqlFuncServices = context.SqlFuncServices;
  61. newContext.Resolve(item, type);
  62. context.Index = newContext.Index;
  63. context.ParameterIndex = newContext.ParameterIndex;
  64. if (newContext.Parameters.HasValue())
  65. context.Parameters.AddRange(newContext.Parameters);
  66. return newContext.Result.GetResultString();
  67. }
  68. public static string GetMethodValueSubJoin(ExpressionContext context, Expression item, ResolveExpressType type)
  69. {
  70. var newContext = context.GetCopyContext();
  71. newContext.MappingColumns = context.MappingColumns;
  72. newContext.MappingTables = context.MappingTables;
  73. newContext.InitMappingInfo = context.InitMappingInfo;
  74. newContext.RefreshMapping = context.RefreshMapping;
  75. newContext.IgnoreComumnList = context.IgnoreComumnList;
  76. newContext.SqlFuncServices = context.SqlFuncServices;
  77. if (type == ResolveExpressType.WhereMultiple||type==ResolveExpressType.FieldMultiple)
  78. {
  79. newContext.IsSingle = false;
  80. }
  81. newContext.Resolve(item, type);
  82. context.Index = newContext.Index;
  83. context.ParameterIndex = newContext.ParameterIndex;
  84. if (newContext.Parameters.HasValue())
  85. context.Parameters.AddRange(newContext.Parameters);
  86. return newContext.Result.GetResultString();
  87. }
  88. }
  89. }