MapperNoKeyExt.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Quadarax.Foundation.Core.Data.Entity;
  6. using Quadarax.Foundation.Core.Data.Interface.Entity;
  7. namespace BO.AppServer.Business.Mapper
  8. {
  9. public static class MapperNoKeyExt
  10. {
  11. public static TDto Map<TDao, TDto>(this TDao dao)
  12. where TDao : class, IDao<NoKey>, new()
  13. where TDto : class, IDto, new()
  14. {
  15. if (dao == null) return null;
  16. return MapperNoKey.Instance.Map<TDao, TDto>(dao);
  17. }
  18. public static TDao MapDto<TDto, TDao>(this TDto dto)
  19. where TDao : class, IDao<NoKey>, new()
  20. where TDto : class, IDto, new()
  21. {
  22. if (dto == null) return null;
  23. return MapperNoKey.Instance.Map<TDto, TDao>(dto);
  24. }
  25. public static void CopyToDto<TDto, TDao>(this TDto @from, TDao to)
  26. where TDao : class, IDao<NoKey>, new()
  27. where TDto : class, IDto, new()
  28. {
  29. if (@from == null) return;
  30. if (to == null) return;
  31. MapperNoKey.Instance.Update(@from,to);
  32. }
  33. public static void CopyToDto<TDto, TDao>(this TDao @from, TDto to)
  34. where TDao : class, IDao<NoKey>, new()
  35. where TDto : class, IDto, new()
  36. {
  37. if (to == null) return;
  38. if (@from == null) return;
  39. MapperNoKey.Instance.Update(@from,to);
  40. }
  41. public static List<TDto> MapList<TDao, TDto>(this IQueryable<TDao> dao)
  42. where TDao : class, IDao<NoKey>, new()
  43. where TDto : class, IDto, new()
  44. {
  45. if (dao == null) return new List<TDto>();
  46. return MapperNoKey.Instance.MapList<TDao, TDto>(dao);
  47. }
  48. public static List<TDto> MapList<TDao, TDto>(this IEnumerable<TDao> dao)
  49. where TDao : class, IDao<NoKey>, new()
  50. where TDto : class, IDto, new()
  51. {
  52. if (dao == null) return new List<TDto>();
  53. return MapperNoKey.Instance.MapList<TDao, TDto>(dao);
  54. }
  55. public static List<TDto> MapList<TDao, TDto>(this IList<TDao> dao)
  56. where TDao : class, IDao<NoKey>, new()
  57. where TDto : class, IDto, new()
  58. {
  59. if (dao == null) return new List<TDto>();
  60. return MapperNoKey.Instance.MapList<TDao, TDto>(dao);
  61. }
  62. public static IQueryable<TDao> MapListDto<TDto,TDao>(this IEnumerable<TDto> dto)
  63. where TDao : class, IDao<NoKey>, new()
  64. where TDto : class, IDto, new()
  65. {
  66. if (dto == null) return new List<TDao>().AsQueryable();
  67. return MapperNoKey.Instance.MapList<TDto, TDao>(dto.AsQueryable()).AsQueryable();
  68. }
  69. }
  70. }