score:0
i found out that visual studio translates it in to selects, so i realized that, the best solution for stuff like this is to make some view.. just giving answer to own q for another guys.
score:0
even though you can get some performance by removing the first, unneeded select (depending on the volume of data this could be minimal to medium improvement) like this:
keyvalues = item.resources
.where(conditionexpression)
.groupby(g => new { g.resourceid, g.language })
.orderbydescending(o => o.changed.hasvalue ? o.changed : o.created)
.select( s => new keyvalues
{
language = s.language,
keyvalue = s.value
}).tolist();
depending on your case, you could:
if your data is in a database, you can create database improvements like adding indexes, updating statistics, using hints etc.
if this is local data, you can use some strategy to split new and old data between various enumerables.
there is no other way to significantly improve your linq query. you need to find another strategy to achieve that.
score:2
as you need only one element after grouping, you can return it right in groupby clause, it will simplify your code:
keyvalues = item.resources
.where(conditionexpression)
.groupby(g => new { g.resourceid, g.language },
(x, y) => new { max = y.orderbydescending(o => o.changed ?? o.created).first() })
.select(s => new keyvalues
{
language = s.max.language,
keyvalue = s.max.value
})
.tolist();
Source: stackoverflow.com
Related Query
- LINQ Lambda efficiency of code groupby orderby
- Linq Lambda GroupBy and OrderBy
- What is the Efficiency and Performance of LINQ and Lambda Expression in .Net?
- Translate SQL to lambda LINQ with GroupBy and Average
- Using GroupBy and Max in LINQ Lambda Expressions
- LINQ to SQL GroupBy Max() lambda
- LINQ Source Code Available
- multiple orderby in this linq code
- Linq - OrderBy the minimum value of two columns using lambda expressions?
- why Linq GroupBy After OrderBy dismissed order operation?
- Generic LINQ orderby lambda function
- LINQ GroupBy then OrderBy Behaviour
- LINQ - sub query using OrderBy and GroupBy
- creating Linq to sqlite dbml from DbLinq source code
- GroupBy OrderBy Linq - invalid column
- GroupBy and OrderBy in LINQ
- LINQ (Dynamic): OrderBy within a GroupBy using dynamic linq?
- Linq or Lambda - Method to allow custom Orderby clause on joined table
- Asp.net LINQ groupby and orderBy on dates does not retrieve the expected output
- where can I find a good example of using linq & lambda expressions to generate dynamic where and orderby sql?
- LINQ GroupBy and then OrderBy a property from the previous query
- source code for LINQ 101 samples
- Linq Sorted Groupby and Orderby fields
- Linq OrderBy then GroupBy - group by unexpectedly changes order of list
- C# Linq XML GroupBy OrderBy get count
- Linq multiple join ,then GroupBy along with OrderBy , tried everything I could find
- LINQ GroupBy Source = A Destination = B or Source = B and Destination = A
- NHibernate Linq MismatchedTreeNodeException, Simple OrderBy and GroupBy
- GroupBy and OrderBy using LINQ
- Help With Generic LINQ OrderBy Lambda Expression
More Query from same tag
- Func declared as a variable used in .Where() crashes my application
- Mocking (moq) a GetAllAsync linq query with select
- How to convert list of string into list of number then apply OrderByDescending on that list in C#
- Left (Outer) Joins with Linq - Contradiction with "into" in examples I found
- Extend a list using last element to match longer list in LINQ zip
- Convert a LINQ Query Resultset to a DataTable
- New to Linq; need to grab multiple values from single row
- Convert an IQueryable linq query to IEnumerable<T> cancels out linq optimized way to work?
- Injecting a variable into the Mono.CSharp.Evaluator (runtime compiling a LINQ query from string)
- Using linq to build a comma delimited string
- How to parse XML file in C# using LINQ?
- what is a projection in LINQ, as in .Select()
- Query with filter builder on nested array using MongoDB C# driver with a given array of string
- Query in LINQ with self join
- Creating dynamic linq expression OData for multiple conditions for filter Contains?
- How to get all DataColumns of a DataTable to Lists
- How to schedule jobs without overlap using LINQ to Objects?
- How to substitute the LINQ Query with lambda expression
- C# linq for loop inside the add method
- mongoDB run queries just like as SQL !
- linq query that joins results from three other queries
- How to change the value of a variable within a child of a nested list
- Dynamic query in linq or lambda expression C#
- linq query with grouping and conditional result
- how to do left join in lambda
- Rule based grouping of data into segments LINQ
- Linq Query returning rows matching all words in array
- Need help optimizing loop with Linq
- Iterator in aggregate (linq)?
- Using value from related table in LINQ where clause