score:0
I'm thinking the query will look something like this
EntityQuery<EmployeeProduct> query = from c in _employ.CountProduct()
group c by new {c.UserId, c.ProductId, c.Name}
into g
select new {
g.UserId,
g.ProductId,
g.Name,
Count = g.Count()
}
score:3
Here's a couple of way to do this:
var employeeProducts = new List<EmployeeProduct>();
employeeProducts.Add(new EmployeeProduct(1, 2, "XYZ"));
employeeProducts.Add(new EmployeeProduct(1, 5, "ZXY"));
employeeProducts.Add(new EmployeeProduct(2, 2, "XYZ"));
var way1 = employeeProducts.Select(
ep => new ProductCount
{
ProductNumber = ep.ProductID,
EmployeeNumber = ep.EmployeeID,
CountProducts = employeeProducts.Count(epc => epc.ProductID == ep.ProductID)
});
var way2 = employeeProducts
.GroupBy(ep => ep.ProductID)
.SelectMany(epg => epg.Select(
ep => new ProductCount
{
ProductNumber = ep.ProductID,
EmployeeNumber = ep.EmployeeID,
CountProducts = epg.Count()
}));
Source: stackoverflow.com
Related Query
- LINQ with groupby and count
- LINQ Source Code Available
- GroupBy String and Count in LINQ
- LINQ Lambda efficiency of code groupby orderby
- Linq Query Count and GroupBy
- creating Linq to sqlite dbml from DbLinq source code
- EF core Linq groupby and having sum count - could not be translated and will be evaluated locally
- LINQ GroupBy Count
- Linq GroupBy Clause not including items with zero count
- Linq groupby list matching and count
- GroupBy using LINQ but base distinct on another column, and still be able to count other records
- Linq groupby and count operations in mvc
- Different result in Linq with GroupBy and Count
- GroupBy and Count with condition using LINQ
- source code for LINQ 101 samples
- Convert SQL Distinct, Count & GroupBy to a Linq query with Navigation
- GroupBy and Count using LINQ
- C# Linq XML GroupBy OrderBy get count
- Linq Age GroupBy Aggregate Count
- LINQ GroupBy Source = A Destination = B or Source = B and Destination = A
- How make a LINQ Select, GroupBy and Count from a List of Lists?
- Linq groupby IdCordinator only if categery type count greater than one
- Convert SQL to Linq - Where, in, Groupby and Having count
- I want to print Count using Groupby and Left join in linq
- Why am I unable to do a count after a GroupBy with LINQ
- linq groupby and max count
- Map Linq groupby count to C# entity
- LINQ GroupBy Month and Color Count
- Linq Code with Distinct or GroupBy not working
- c# Linq or code to extract groups from a single list of source data
More Query from same tag
- Multiple rows update without select
- Linq skip is skipping the wrong results?
- A lambda expression with a statement body cannot be converted to an expression tree(Lambda and Linq)
- Linq for taking values in variable through select query
- Replace repeated values in collection with its sum
- dilemma on the use of inheritance in EF code-first
- LINQ Room id where user exists
- Learning LINQ: QuickSort
- Linqify this: Aggregate a subset of a list
- Where clause not entering lambda
- LINQ: dynamic Where clause with toggle the combination of cases
- Linq.NHibernate problem with OR statement
- Entity Framework ThenInclude filtered from original dataset
- LINQ to SQL selecting all records which have any word in the string split
- Get data from three tables by ID C# APi
- Filtering Enteties in EF 6.0 with WPF and MySql
- Split a list into sublist by checking a condition on elements
- OrderBy Expression Tree in Net Core Linq for Extension Method
- C# - Method with Generic Property
- How can I iterate over several IEnumerables simultaneously
- How do I write the Linq query to get complex model items?
- How to only return a list of inherited instances if defined, otherwise return the base class
- In a LINQ statement using closures, is it possible to specify a where clause within a closure?
- How to get an outerjoin on a Linq query
- Entity framework 6 lazy loading oddity
- Closing a window in WPF MVVM
- LINQ, Left Join, throwing exception...failed because the materialized value is null
- 'string' does not contain a definition for 'Contains'
- Invoking HashSet.Add(item) in Linq vs foreach loop
- Splitting an array into 2 arrays C#