Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Product
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public decimal Price { get; set; }
- public bool IsAvailable { get; set; }
- public virtual ICollection<Product> ChildProducts { get; set; }
- }
- public class ProductDTO
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public decimal Price { get; set; }
- public virtual ICollection<Product> ChildProducts { get; set; }
- }
- public IQueryable<ProductDto> GetProductsDto()
- {
- var products = ProductContext.DbSet.ProjectTo<PoductDto>();
- Logger.Debug($"{products.Count()}");
- return products.AsQueryable();
- }
- CreateMap<Product, ProductDto>()
- .ForMember(dest => dest.ChildProducts,
- opt =>
- {
- opt.Condition(x => x.ChildProducts.Any(child => child.IsAvailable == true));
- })
- .MaxDepth(1) //Set the Max Depth of Expands
- .PreserveReferences();
Add Comment
Please, Sign In to add comment