Linq query across three levels of tables to generate sum?

Without trying to compile it, I think this will work the way you want. It assumes that you have the associations set up in the LINQ to SQL data context var transPerCategory = db. Categories .

Select( c => new { Name = c. CategoryName, Amount = c. Products .

Sum( p => p. Transactions . Sum( t => t.

TransactionAmount ) ) }).

Without trying to compile it, I think this will work the way you want. It assumes that you have the associations set up in the LINQ to SQL data context. Var transPerCategory = db.

Categories . Select( c => new { Name = c. CategoryName, Amount = c.

Products . Sum( p => p. Transactions .

Sum( t => t. TransactionAmount ) ) }).

I have a series of tables that are joined with Primary Key/Foreign Key relationships. I have a table of Transactions, and each Transaction references one and only one Product. I'm just learning LinqToSql, and I've used lambda expressions to access the Products in each category (x => x.

But what I'm trying to do is access the Transactions table, specifically to get a sum of all transactions by category. I'm sure I could do this by creating manual Joins in my Linq statement. But it doesn't seem like I should have to do this, since all of my tables are joined as PF/FK in the model.

Can anyone offer an example of how to get started?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions