У меня проблема с
IEnumerable<SelectedProductRequest> selectedProducts = {
new SelectedProductRequest {id = 4, Name = "product1", Price = 23},
new SelectedProductRequest {id = 4, Name = "product1", Price = 44},
new SelectedProductRequest {id = 5, Name = "product2", Price = 11}
}
List<MyProducts> myProducts= {
new MyProducts{id = 4, Name = "product1", isExcl= true},
new MyProducts{id = 5, Name = "product2", isExcl= false}
}
IEnumerable<SelectedProductViewModel> products = myProducts
.Select(product => new SelectedProductViewModel(
product.Name,
selectedProducts.FirstOrDefault(selectedProduct => selectedProduct.id== product.id)?.Price ?? 0,
product.IsExclusive))
.OrderByDescending(product => product.id)))
Продукты должны возвращать:
products= {
new SelectedProductRequest {id = 4, Name = "product1", Price = 23, IsExclusive = true},
new SelectedProductRequest {id = 4, Name = "product1", Price = 44, IsExclusive = true},
new SelectedProductRequest {id = 5, Name = "product2", Price = 11, IsExclusive = false}
}
Что я получаю:
products= {
new SelectedProductRequest {id = 4, Name = "product1", Price = 23, IsExclusive = true},
new SelectedProductRequest {id = 5, Name = "product2", Price = 11, IsExclusive = false}
}
И это из-за FirstOrDefault , у вас есть идеи, как мне достичь желаемого результата?