score:2
Accepted answer
var result = db.tblprocessorlists.groupjoin( // groupjoin processors and transactions
db.tbltransactions,
processor => processor.userid, // from every processor take the userid
transaction => transaction.userid, // from every transaction take the userid
// resultselector: use eacht processor with its zero or more matching transactions
// to make one new object
(processor, transactionsofthisprocessor) => new
{
processor = processor,
// group all transactionsofthisprocessor into groups with same [year, month]
// and sum the values of all transactions in each group
transactiontotals = transactionsofthisprocessor
.groupby(transaction => new
{
year = transaction.year, // keyselector: make groups with
month = transaction.month // same [year, month]
},
// element selector: transaction.value
transaction => transaction.value,
// resultselector: key = [year, month],
// elements are all values of this [year, month] group
// sum all values
(key, valueswiththisyearmonth) => new
{
year = key.year,
month = key.month,
total = valueswiththisyearmonth.sum(),
}),
});
Source: stackoverflow.com
Related Query
- List Categories and it's count of products with LinQ using Lambda or classic expressions
- How apply a method to all list members using very short linq with lambda omitted?
- Filter LINQ query using items from an external list with Lambda
- Querying MongoDB with List of IDs using Lambda Expression
- Filter with several nullable conditions an IEnumerable - List using lambda expressions
- List with in List using Lambda
- Using a list of Json results as parameters for a mvc actionresult, to return objects from database with Linq and Lambda
- join two or more list with Lambda but not using the method or type "Join"
- Populate a list with a specific range of numbers by using LINQ
- Using FluentValidation's WithMessage method with a list of named parameters
- How to query a nested list using a lambda expression
- How can anonymous types be created using LINQ with lambda syntax?
- Convert or map a list of class to another list of class by using Lambda or LINQ?
- How to update an element with a List using LINQ and C#
- Using a LINQ ExpressionVisitor to replace primitive parameters with property references in a lambda expression
- Using Lambda with Dictionaries
- Access nested properties with dynamic lambda using Linq.Expression
- Using Lambda Expressions trees with IEnumerable
- How to rewrite this LINQ using join with lambda expressions?
- Using LINQ to Get Sum/ Average of a List with custom objects
- How can I filter a list of objects using lambda expression?
- How to set multiple values in a list using lambda expression?
- Return List with Maximum Count using Linq
- Using async with Entity Framework select list of type IQueryable<T>
- Execute method for each object in generic list using lambda
- How to convert list of objects with two fields to array with one of them using LINQ
- Difference of two List with different types using LINQ
- Using Linq to compare a list with a set of lists in C#
- Converting list with nested list to a separate list using Linq
- Modify elements in list with ForEach lambda
More Query from same tag
- Get Names from a table, using LINQ (EF) with a specific suffix
- How would I convert only a subset of column values from a DataRow into a string array using LINQ?
- LINQ query as parameter in function C#
- Replace LINQ method with inline LINQ expression
- How to execute "Parallel.ForEach" as background task that will return control immediate to the calling method?
- IN Operator between 2 collection objects
- Using LINQ to iterate through a database and generate a generic XML layout of schema + data
- Include null cells in Linq query from DB in C# code
- Get a specific info from an other table with Linq
- Selecting similar elements from same list
- How to do datatemplate for items in listbox?
- How can I run a paged query in EF Core if Skip and Take are always evaluated locally?
- How can I use external expressions in Linq with EF4 (and LINQKit)?
- LINQ-to-entities - Null reference
- LINQ query left joining two tables with concatenation
- How should I get the length of an IEnumerable?
- How to convert Null to String with Linq to Entity
- Understanding lazy evaluation in LINQ in C#
- What is the difference between using the Dump() extension method and using the Console.WriteLine() in the LINQPad?
- Dynamically build a condition on a DataTable using a Dictionary
- Linq to Sql .Except not working if null in C#
- Cannot applied to Operands of Type 'IEnumerable<DateTime>' and `DateTime` ( >= & <=)
- LINQ in MVC Razor View
- Select a specific range of elements?
- Grouping & Sorting in linq
- How to get total results count before .Take() - but when using .Take()
- Selecting inner object of the list
- LINQ - How to get data from multiple tables
- Linq join two objects of the same type
- Code First Entity Framework Linq Statement Returning Missing Records