You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.0 KiB

2 years ago
  1. using System.Linq;
  2. using System.Linq.Expressions;
  3. namespace SqlSugar
  4. {
  5. public class SubOrderBy : ISubOperation
  6. {
  7. public string Name
  8. {
  9. get { return "OrderBy"; }
  10. }
  11. public Expression Expression
  12. {
  13. get; set;
  14. }
  15. public int Sort
  16. {
  17. get
  18. {
  19. return 480;
  20. }
  21. }
  22. public ExpressionContext Context
  23. {
  24. get; set;
  25. }
  26. public string GetValue(Expression expression)
  27. {
  28. var exp = expression as MethodCallExpression;
  29. var argExp = exp.Arguments[0];
  30. var result = "ORDER BY " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle);
  31. var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
  32. result = result.Replace(selfParameterName, string.Empty);
  33. return result;
  34. }
  35. }
  36. public class SubOrderByDesc : ISubOperation
  37. {
  38. public string Name
  39. {
  40. get { return "OrderByDesc"; }
  41. }
  42. public Expression Expression
  43. {
  44. get; set;
  45. }
  46. public int Sort
  47. {
  48. get
  49. {
  50. return 480;
  51. }
  52. }
  53. public ExpressionContext Context
  54. {
  55. get; set;
  56. }
  57. public string GetValue(Expression expression)
  58. {
  59. var exp = expression as MethodCallExpression;
  60. var argExp = exp.Arguments[0];
  61. var result = "ORDER BY " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle)+" DESC";
  62. var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
  63. result = result.Replace(selfParameterName, string.Empty);
  64. return result;
  65. }
  66. }
  67. }