Guest User

Untitled

a guest
Oct 19th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. public class Product
  2. {
  3. public int Id { get; set; }
  4. public string Name { get; set; }
  5. public decimal Price { get; set; }
  6. public bool IsAvailable { get; set; }
  7.  
  8. public virtual ICollection<Product> ChildProducts { get; set; }
  9. }
  10.  
  11. public class ProductDTO
  12. {
  13. public int Id { get; set; }
  14. public string Name { get; set; }
  15. public decimal Price { get; set; }
  16.  
  17. public virtual ICollection<Product> ChildProducts { get; set; }
  18. }
  19.  
  20. public IQueryable<ProductDto> GetProductsDto()
  21. {
  22. var products = ProductContext.DbSet.ProjectTo<PoductDto>();
  23. Logger.Debug($"{products.Count()}");
  24. return products.AsQueryable();
  25. }
  26.  
  27. CreateMap<Product, ProductDto>()
  28. .ForMember(dest => dest.ChildProducts,
  29. opt =>
  30. {
  31. opt.Condition(x => x.ChildProducts.Any(child => child.IsAvailable == true));
  32. })
  33. .MaxDepth(1) //Set the Max Depth of Expands
  34. .PreserveReferences();
Add Comment
Please, Sign In to add comment