EntityColumnExtension.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace SqlSugar
  8. {
  9. public static class EntityColumnExtension
  10. {
  11. public static EntityColumnable<T> IfTable<T>(this EntityColumnInfo entityColumnInfo)
  12. {
  13. EntityColumnable<T> result = new EntityColumnable<T>();
  14. result.entityColumnInfo = entityColumnInfo;
  15. result.IsTable = entityColumnInfo.EntityName == typeof(T).Name;
  16. return result;
  17. }
  18. }
  19. public class EntityColumnable<T>
  20. {
  21. public EntityColumnInfo entityColumnInfo { get; set; }
  22. public bool IsTable { get; set; }
  23. public EntityColumnable<T> UpdateProperty(Expression<Func<T,object>> propertyExpression,Action<EntityColumnInfo> updateAction)
  24. {
  25. var name = ExpressionTool.GetMemberName(propertyExpression);
  26. if (entityColumnInfo.PropertyName == name && IsTable)
  27. {
  28. updateAction(entityColumnInfo);
  29. }
  30. return this;
  31. }
  32. public EntityColumnable<T> OneToOne(Expression<Func<T, object>> propertyExpression,string firstName, string lastName=null)
  33. {
  34. var name = ExpressionTool.GetMemberName(propertyExpression);
  35. if (entityColumnInfo.PropertyName == name && IsTable)
  36. {
  37. entityColumnInfo.Navigat = new Navigate(NavigateType.OneToOne, firstName, lastName);
  38. entityColumnInfo.IsIgnore = true;
  39. }
  40. return this;
  41. }
  42. public EntityColumnable<T> OneToMany(Expression<Func<T, object>> propertyExpression, string firstName, string lastName)
  43. {
  44. var name = ExpressionTool.GetMemberName(propertyExpression);
  45. if (entityColumnInfo.PropertyName == name && IsTable)
  46. {
  47. entityColumnInfo.Navigat = new Navigate(NavigateType.OneToMany, firstName, lastName);
  48. entityColumnInfo.IsIgnore = true;
  49. }
  50. return this;
  51. }
  52. public EntityColumnable<T> ManyToMany(Expression<Func<T, object>> propertyExpression,Type mapppingType, string mapppingTypeAid, string mapppingTypeBid)
  53. {
  54. var name = ExpressionTool.GetMemberName(propertyExpression);
  55. if (entityColumnInfo.PropertyName == name && IsTable)
  56. {
  57. entityColumnInfo.Navigat = new Navigate(mapppingType, mapppingTypeAid, mapppingTypeBid);
  58. entityColumnInfo.IsIgnore = true;
  59. }
  60. return this;
  61. }
  62. }
  63. }