SubSelectStringJoin.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 SubSelectStringJoin : ISubOperation
  9. {
  10. public bool HasWhere
  11. {
  12. get; set;
  13. }
  14. public string Name
  15. {
  16. get
  17. {
  18. return "SelectStringJoin";
  19. }
  20. }
  21. public Expression Expression
  22. {
  23. get; set;
  24. }
  25. public int Sort
  26. {
  27. get
  28. {
  29. return 200;
  30. }
  31. }
  32. public ExpressionContext Context
  33. {
  34. get; set;
  35. }
  36. public string GetValue(Expression expression = null)
  37. {
  38. var exp = expression as MethodCallExpression;
  39. //var entityType = (exp.Arguments[0] as LambdaExpression).Parameters[0].Type;
  40. //if (this.Context.InitMappingInfo != null)
  41. //{
  42. // this.Context.InitMappingInfo(entityType);
  43. // this.Context.RefreshMapping();
  44. //}
  45. InitType(exp);
  46. var result = "";
  47. if (this.Context.JoinIndex == 0)
  48. result = SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle);
  49. else
  50. result = SubTools.GetMethodValueSubJoin(this.Context, exp.Arguments[0], ResolveExpressType.FieldMultiple);
  51. SetShortName(exp, result);
  52. result = this.Context.DbMehtods.GetStringJoinSelector(result, ExpressionTool.GetExpressionValue(exp.Arguments[1]) + "");
  53. return result;
  54. }
  55. private void InitType(MethodCallExpression exp)
  56. {
  57. foreach (var arg in (exp.Arguments[0] as LambdaExpression).Parameters)
  58. {
  59. if (this.Context.InitMappingInfo != null)
  60. {
  61. this.Context.InitMappingInfo(arg.Type);
  62. this.Context.RefreshMapping();
  63. }
  64. }
  65. }
  66. public void SetShortName(MethodCallExpression exp, string result)
  67. {
  68. if (exp.Arguments[0] is LambdaExpression )
  69. {
  70. var parameters = (exp.Arguments[0] as LambdaExpression).Parameters;
  71. if (parameters != null && parameters.Count > 0)
  72. {
  73. this.Context.CurrentShortName = this.Context.GetTranslationColumnName(parameters[0].ObjToString());
  74. }
  75. }
  76. }
  77. public void SetShortNameNext(MethodCallExpression exp, string result)
  78. {
  79. if (exp.Arguments.Count > 1 && exp.Arguments[1] is LambdaExpression )
  80. {
  81. var parameters = (exp.Arguments[1] as LambdaExpression).Parameters;
  82. if (parameters != null && parameters.Count > 0)
  83. {
  84. this.Context.CurrentShortName = this.Context.GetTranslationColumnName(parameters[0].ObjToString());
  85. }
  86. }
  87. }
  88. }
  89. }