Код: Выделить всё
ImageКод: Выделить всё
public class Image : EntityBase
{
[Required]
public string Url { get; set; } = string.Empty;
[Required]
public Guid EntityId { get; set; }
[Required]
public EntityType EntityType { get; set; } // enum: Product, Company, etc.
public DateTime CreatedAt { get; set; }
}
< /code>
ProductКод: Выделить всё
public class Product : EntityBase
{
[Required, MaxLength(150)]
public string Name { get; set; } = string.Empty;
public string? Description { get; set; }
[Required]
public Guid CompanyId { get; set; }
public Company? Company { get; set; }
[Required]
public Guid? ThumbnailImageId { get; set; }
public ICollection Items { get; set; } = [];
public DateTime CreatedAt { get; set; }
}
< /code>
In my CQRS query handler, I use a specification to filter and paginate products, and then project them into a DTO:
public class GetProductsQueryHandler : IRequestHandler>
{
private readonly IRepository _productRepository;
private readonly IRepository _imageRepository;
public GetProductsQueryHandler(IRepository productRepository, IRepository imageRepository)
{
_productRepository = productRepository;
_imageRepository = imageRepository;
}
public async Task Handle(GetProductsQuery request, CancellationToken cancellationToken)
{
var spec = new ProductSearchSpecification(request.ProductFilter, request.PageNumber, request.PageSize);
Expression selector = product => new ProductResponse(
product.Id,
product.Name,
product.Description,
product.Company!.Name,
product.CompanyId,
product.CreatedAt
// How to include the image URL here?
);
var products = await _productRepository.GetPaggedListAsync(spec, selector, cancellationToken);
return Result.Success(products);
}
}
< /code>
[b]My question[/b]: how can I cleanly (Best Practices) and efficiently include the thumbnail image URL (from the ImageПодробнее здесь: https://stackoverflow.com/questions/796 ... erties-are
Мобильная версия