score:2
Accepted answer
goals = await _context.fixtureactivitytb.where(p => p.activitytype.trim() == "g")
.groupby(p => p.playerid)
.join(_context.playertb, x => x.key, j => j.playerid, (x, j)
=> new stats
{
name = j.givenname,
pid = j.playerid,
teamid = j.teamid,
count = x.count()
})
.orderbydescending(s => s.count)
.thenby(s => s.name)
.take(10)
.tolistasync();
score:0
var q = from p in _context.fixtureactivitytb
where p.activitytype.trim() == "g"
group p by p.playerid into x
join j in _context.playertb on x.key equals j.playerid
select new stats
{
name = j.givenname,
pid = j.playerid,
teamid = j.teamid,
count = x.count()
};
goals = await q.orderbydescending(s => s.count)
.thenby(s => s.name)
.take(10)
.tolistasync();
Source: stackoverflow.com
Related Query
- I have a LINQ statement that is partially query and partially method. How can I do this using one or the other?
- How can I simplify this LINQ query that searches for keywords in strings and orders them by relevance?
- How to refactor a MongoDB .NET LINQ Query that uses a static method in a select statement
- How can I convert Sql query to Linq and its equivalent with Join() method in Entity Framework Core
- How to handle a linq query that returns zero rows and have it return decimal value?
- How can I create a method that will print LINQ query results?
- Why does C# compiler create private DisplayClass when using LINQ method Any() and how can I avoid it?
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- How can I have a linq query conditionally NOT apply a where clause
- How can I optmize a "select all" statement in linq that casts ~4000 rows to objects?
- How can I perform a LINQ Query and select?
- How can I write a method to build a query both for SQL and an array?
- How can I have a LINQ where clause that does nothing?
- How to convert this LINQ query syntax that connects two objects to method syntax?
- How do you write a LINQ query that filters a sub table to a specific time period and sums the results of the sub table?
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- How can I set custom property of an Entity type in LINQ to Entities query and still return a IQueryable<T>?
- Is there any way to encapsulate a simple LINQ query in an extension method that can be used with LINQ to Entities query?
- How to return query results from method that uses LINQ to SQL
- How can I access elements in a LINQ query that is utilizing a groupBy?
- How can I do a LINQ query joining two entities and select what a Where on one of the entities?
- How to write a linq statement that parses and checks value of a list
- How can I refine a linq query that binds to a DTO via another list?
- How does Linq projection work between Extention Method and query expression
- How can I build a LINQ predicate/dynamic.LINQ query based off grid filtering when the grid properties don't have the entity properties?
- How do I call a method from within a linq query that is retrieving from an Entity Framework model
- linq lamba how can i query a list of child properties and return the parent
- How Can i retrieve date from a hashset that contains date and name using linq or contains?
- How to simplify this LINQ to Entities Query to make a less horrible SQL statement from it? (contains Distinct,GroupBy and Count)
- How can I use custom expressions in DevArt LINQ to Entities and also use query comprehension syntax?
More Query from same tag
- List of objects where the object contains an array - how to use LINQ to search through all objects for a value in that array
- How to group a list of data into year, season, month, week, day?
- JSON.NET Argument Exception when creating JSON with LINQ
- How can I do this LINQ query in BreezeJS?
- Do I have to use CopyTo to get a custom collection into an enumerable?
- Select objects from a list using LINQ based on a property
- Adding more parameters to a Linq query
- Entity Framework - Convert an SQL query to Entity Framework Lambda expression
- Linq: Joining two tables
- LINQ to Entities does not recognize the method
- Future-proof way to specify a MethodInfo via a Linq Expression
- Issue With LINQ and Reference List
- How to Select All Fields in Linq to Entity Using Lambda Expression?
- Get difference between two data-tables according to one column
- Writing LINQ queries. Joins VS navigational properties
- Any way I can run custom LINQ during debug / breakpoint in VS2010 or otherwise?
- How to get a copy of data instead of a reference using linq/lambda in c#?
- C# linq expression in lambda with contains
- C# Left join in LINQ
- Nullable Bit field true or false detection
- How to add documents in Lucene.Net.Linq?
- LINQ query returns null reference only after adding where clause
- How to flatten nested objects with linq expression
- C#: 'IEnumerable<Student>' does not contain a definition for 'Intersect'
- How to use LINQ to reduce a <string,list<string>> to <string,string>?
- How to handle exception raised in linq
- Always exclude property from Entity Framework 4 Query
- Linq Extension Method - GetYearWeekFormat Extension
- Moving ten files at a time using Vb.NET
- Covariance/Contravariance with a linq expression