Skip to content

Instantly share code, notes, and snippets.

@andrebaltieri
Created January 9, 2022 16:29
Show Gist options
  • Save andrebaltieri/1d72c8d4db3e90f30ef5183b72acb3cb to your computer and use it in GitHub Desktop.
Save andrebaltieri/1d72c8d4db3e90f30ef5183b72acb3cb to your computer and use it in GitHub Desktop.
var orders = new List<Order>
{
new("Order 1 -10 itens", GenerateOrderLines(9)),
new("Order 2 +10 itens ", GenerateOrderLines(12)),
new("Order 3 +10 itens", GenerateOrderLines(18)),
new("Order 4 +10 itens", GenerateOrderLines(22))
};
List<OrderLine> GenerateOrderLines(int quantity)
{
var result = new List<OrderLine>();
for (var i = 0; i < quantity; i++)
result.Add(new OrderLine($"Product {i}", i, i));
return result;
}
var data =
from order in orders
let totalItems = order.OrderLines.Count
let total = order.OrderLines.Sum(x => x.Price)
where
totalItems > 10 &&
total > 100
select order;
foreach (var item in data)
Console.WriteLine($"{item.Number} - {item.OrderLines.Sum(x => x.Price)}");
public record Order(string Number, List<OrderLine> OrderLines);
public record OrderLine(string Product, int Quantity, decimal Price);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment