score:3
Accepted answer
DateTime last60Days = new DateTime(xxx,xxx,xxx);
var query = from u in context.Users
group u by new
{
u.Forename,
u.Surname
} into ug
select new
{
Forename = ug.Key.Forename,
Surname = ug.Key.Surname,
MaxOrderdate = ug.SelectMany(x => x.Orders).Max(x => x.OrderDate),
OrderCount = ug.SelectMany(x => x.Orders).Count(),
Payment = ug.SelectMany(x => x.Orders.SelectMany(y => y.Payments)).Sum(x => x.PaymentAmount),
OrderCountLast60 = ug.SelectMany(x => x.Orders).Where(x => x.OrderDate > last60Days).Count(),
PaymentLast60 = ug.SelectMany(x => x.Orders.Where(x => x.OrderDate > last60Days).SelectMany(y => y.Payments)).Sum(x => x.PaymentAmount)
};
Source: stackoverflow.com
Related Query
- EF Return Aggregated and Non-Aggregated Data
- I am wondering about the state of connection and impact on code performance by 'yield' while iterating over data reader object
- How can I compare two sets of data in linq and return the common data?
- LINQ and creating NON anonymous return values
- Return LINQ Query and INSERT Data
- How do I return single data from primary table and multiple entries in second table nested after join
- Joining data that exists in two tables and aggregating non joined data
- Linq to CSV : Convert data to .CSV file and return file from an action without saving file on the server
- Call to Task<> method inside LINQ and return data
- SQL code to join to, and sum data in, a table referenced by comma delimited keys
- join two datatable and return the result in another data table
- How do I group items from a collection using LINQ and return the shaped data according the collection type
- How to hit a url from controller in MVC 5 and get the return data from that url to perform some task
- How to compare two List content data and return mismatch value?
- How to concatenate column data and return in linq select
- join two lists and check for the matched property value and return the required data
- c# Linq or code to extract groups from a single list of source data
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- I want to union together four queries and set this to be the repeater's data source
- Using LINQ to query XML and return empty string if no data is present
- Compare Two List and return Data from first list based on Ids in Linq C#
- Problem with filtering data by prefix and return collection of proper data with LINQ
- How to find duplicates of particular column in data table in C# and return the duplicate's row number as output
- Using C# Linq find and return a string value from a multi-level data store
- Sum of two column from different table and it should return result if secondary table does not have any data
- How to return this data and populate a Select element
- How to perform .Max() on a property of all objects in a collection and return the object with maximum value
- How to check if all list items have the same value and return it, or return an “otherValue” if they don’t?
- How can I filter a dictionary using LINQ and return it to a dictionary from the same type
- Find() and First() throws exceptions, how to return null instead?
More Query from same tag
- LINQ queries on possibly infinite lists
- Partitioned List<T>?
- C# Linq to XML not working with
- How to rewrite these LINQ statements into one query
- How to add conditional inside Linq Aggregate in C#?
- How to search in a list whether a list of given items exists in the same order
- Mapping Linq Query results to a DTO class
- Querying a Array with list of anonymous Object
- two tables with multiple joining conditions in lambda expressions
- Linq query result changing not working
- How can I compare two IEnumerable<> objects and return a new one?
- Iterating Through a List and Conditionally Setting a Member - Comparison Of Approaches
- Check duplicate GridEX rows with Linq does'nt work
- Null exception being thrown by LINQ to EF
- how to convert a datatable to List<long,List<keyvaluepair<string,string>>> in C#
- What is the correct way to deserialize?
- How to query an embedded XML file using LINQ?
- Linq Group result to an Object
- Retrieve count against each entry in one table from some other table in a single view in mvc
- Linq ToDictionary returns an anonymous type
- Order list of objects by a list of ids
- LINQ - Getting all child records from all parents
- Generic extension methods in LINQ
- Additional conditions to join
- How to compare same property value regardless of order or duplication in multiple models
- translate first_value over partition by to linq
- How to avoid Iterator method being restarted?
- How To: Use LINQ to search data for a string containing many possible types of "Single Quote"
- LINQ to SQL with group by clause with aggregate function
- Project dictionary whose value is a dictionary into a new dictionary whose value is an aggregate