SubFromTable.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 SubFromTable : ISubOperation
  9. {
  10. public bool HasWhere
  11. {
  12. get; set;
  13. }
  14. public string Name
  15. {
  16. get
  17. {
  18. return "Subqueryable";
  19. }
  20. }
  21. public Expression Expression
  22. {
  23. get; set;
  24. }
  25. public int Sort
  26. {
  27. get
  28. {
  29. return 300;
  30. }
  31. }
  32. public ExpressionContext Context
  33. {
  34. get;set;
  35. }
  36. public string GetValue(Expression expression)
  37. {
  38. var exp = expression as MethodCallExpression;
  39. var resType = exp.Method.ReturnType;
  40. var entityType = resType.GetGenericArguments().First();
  41. this.Context.SubTableType = entityType;
  42. var name = entityType.Name;
  43. if (this.Context.InitMappingInfo != null)
  44. {
  45. this.Context.InitMappingInfo(entityType);
  46. this.Context.RefreshMapping();
  47. }
  48. var result= "FROM "+this.Context.GetTranslationTableName(name,true);
  49. if (this.Context.SubQueryIndex > 0) {
  50. result += " subTableIndex"+this.Context.SubQueryIndex;
  51. }
  52. return result;
  53. }
  54. }
  55. }