I use Entity Framework 6, I have such database structure (simplified):
Transactions - Id - DateTime - ...
Products - Id - Name
TransactionsItems - Id - TransactionId - ProductId
As you see relation Transaction <-> Product is many to many type.
I don't know how to group transactions by products using LINq - something like
transactions.GroupBy(t => t.TransactionsItems.Product)
where TransactionsItems property is navigation property generated by entity framework and contains collection of items related to this transaction.
I know I can iterate all products and then search for transactionItems and accumulate data, but I wonder whether is there any simplier method to achieve my goal?
Maybe you just got to group by a specific column :
transactions.GroupBy(t => t.TransactionsItems.Product.Name)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With