UpdateNavMethodInfo.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace SqlSugar
  8. {
  9. public class UpdateNavMethodInfo
  10. {
  11. internal object MethodInfos { get; set; }
  12. internal SqlSugarProvider Context { get; set; }
  13. public UpdateNavMethodInfo IncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions = null)
  14. {
  15. var type = MethodInfos.GetType().GetGenericArguments()[0];
  16. var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type);
  17. Type properyItemType;
  18. bool isList;
  19. Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType, out isList);
  20. var method = this.MethodInfos.GetType().GetMyMethod("Include", 2, isList)
  21. .MakeGenericMethod(properyItemType);
  22. var obj = method.Invoke(this.MethodInfos, new object[] { exp, updateNavOptions });
  23. this.MethodInfos = obj;
  24. return this;
  25. }
  26. public UpdateNavMethodInfo ThenIncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions = null)
  27. {
  28. var type = MethodInfos.GetType().GetGenericArguments()[1];
  29. var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type);
  30. Type properyItemType;
  31. bool isList;
  32. Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType, out isList);
  33. var method = this.MethodInfos.GetType().GetMyMethod("ThenInclude", 2, isList)
  34. .MakeGenericMethod(properyItemType);
  35. var obj = method.Invoke(this.MethodInfos, new object[] { exp, updateNavOptions });
  36. this.MethodInfos = obj;
  37. return this;
  38. }
  39. public async Task<bool> ExecuteCommandAsync()
  40. {
  41. if (Context == null) return false;
  42. var result = MethodInfos.GetType().GetMethod("ExecuteCommandAsync").Invoke(MethodInfos, new object[] { });
  43. return await (Task<bool>)result;
  44. }
  45. public bool ExecuteCommand()
  46. {
  47. if (Context == null) return false;
  48. var result = MethodInfos.GetType().GetMethod("ExecuteCommand").Invoke(MethodInfos, new object[] { });
  49. return (bool)result;
  50. }
  51. }
  52. }