SubTop.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 SubTop : ISubOperation
  9. {
  10. public bool HasWhere
  11. {
  12. get; set;
  13. }
  14. public ExpressionContext Context
  15. {
  16. get; set;
  17. }
  18. public Expression Expression
  19. {
  20. get; set;
  21. }
  22. public string Name
  23. {
  24. get
  25. {
  26. return "Top";
  27. }
  28. }
  29. public int Sort
  30. {
  31. get
  32. {
  33. if (this.Context is SqlServerExpressionContext || this.Context.GetType().Name.Contains("Access"))
  34. {
  35. return 150;
  36. }
  37. else if (this.Context is OracleExpressionContext) {
  38. return 401;
  39. }
  40. else
  41. {
  42. return 490;
  43. }
  44. }
  45. }
  46. public string GetValue(Expression expression)
  47. {
  48. if (this.Context is SqlServerExpressionContext|| this.Context.GetType().Name.Contains("Access"))
  49. {
  50. return "TOP 1";
  51. }
  52. else if (this.Context is OracleExpressionContext)
  53. {
  54. return (HasWhere?"AND":"WHERE")+ " ROWNUM=1";
  55. }
  56. else if (this.Context is PostgreSQLExpressionContext)
  57. {
  58. return "limit 1";
  59. }
  60. else if (this.Context.GetLimit()!=null)
  61. {
  62. return this.Context.GetLimit();
  63. }
  64. else
  65. {
  66. return "limit 0,1";
  67. }
  68. }
  69. }
  70. }