DeleteNavMethodInfo.cs 2.4 KB

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