score:1
maybe this can help. where db is the database context:
(
from pv1 in db.propertyvalues
from pv2 in db.propertyvalues.where(a=>a.property_id==pv1.property_id && pv1.revision<pv2.revision).defaultifempty()
join p in db.properties
on pv1.property_id equals p.id
where pv2.id==null
orderby p.id
select new
{
p.id,
pv1.stringvalue,
pv1.revision
}
);
score:0
if you want to use multiple conditions (less than expression) in join you can do this like
from pv1 in db.propertyvalues
join pv2 in db.propertyvalues on new{pv1.property_id, condition = pv1.revision < pv2.revision} equals new {pv2.property_id , condition = true} into temp
from t in temp.defaultifempty()
join p in db.properties
on pv1.property_id equals p.id
where t.id==null
orderby p.id
select new
{
p.id,
pv1.stringvalue,
pv1.revision
}
score:1
next to optimizing a query in linq to entities, you also have to be aware of the work it takes for the entity framework to translate your query to sql and then map the results back to your objects.
comparing a linq to entities query directly to a sql query will always result in lower performance because the entity framework does a lot more work for you.
so it's also important to look at optimizing the steps the entity framework takes.
things that could help:
- precompile your query
- pre-generate views
- decide for yourself when to open the database connection
- disable tracking (if appropriate)
here you can find some documentation with performance strategies.
Source: stackoverflow.com
Related Query
- How to improve LINQ to EF performance
- Linq join on objects with navigation property - how to improve performance
- How to improve performance of my linq query?
- how to improve LInQ performance repository pattern
- How to improve the performance of a LINQ query that compares two lists?
- How to improve linq performance with large collections (Code first POCO class)
- How are people unit testing code that uses Linq to SQL
- How to improve a push data pipeline in C# to match F# in performance
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- Improve LINQ performance
- How to pass LinQ Expressions from F# to C# code
- How to reuse a linq expression for 'Where' when using multiple source tables
- Will indexing a SQL table improve the performance of a LINQ statement?
- How does linq actually execute the code to retrieve data from the data source?
- LINQ Source Code Available
- How can I switch that code to use LINQ
- How does this linq code that splits a sequence work?
- How to improve this query performance in Linq?
- How to improve my LINQ
- How can I combine this code into one or two LINQ queries?
- How can i improve the performance of this LINQ?
- Linq IEnumerable Extension Method - How to improve performance?
- linq - how do you do a query for items in one query source that are not in another one?
- How can I write the following code more elegantly using LINQ query syntax?
- How can I further simplify this piece of LINQ code
- How can I code an outer join using LINQ and EF6?
- How to dynamic add filters to a LINQ query against an Odata Source in C#
- How to Improve Linq query perfomance regarding Trim()
- How to improve this LINQ query for search
- How to code the partial extensions that Linq to SQL autogenerates?
More Query from same tag
- How do I write this crosstab type query in Linq (tables & data provided)
- Create a method which create dynamic expression
- AsEnumerable().Take
- How to successfully query a database for 0 applicants using LINQ
- Fetching data using LINQ in C#
- Left Join in Linq and using the variable for other joins
- How do I pass an Entity Object to a function in C#
- Better LINQ query to set value of property based on condition
- Why is C# OrderBy so fast?
- Entity Framework Filtering with a List of String
- LINQ query finds subclass in an ObservableCollection of base class
- How to get a dictionary with Linq where keys are met more than once?
- HtmlAgilityPack select only inner text Node
- Linq-to-sql user generated predicate
- Get Directory Structure using Linq?
- Saving the result of a linq query to an XML file
- LINQ intersect, multiple lists, some empty
- linq to xml. read. and assign to ViewData..noob
- LinqToSql query execution timing
- Why do I need distinct with this LINQ query but not with SQL
- Common function to avoid code duplication for handling 2 different type of object
- complex case statement using LinQ to sql
- How to assert a Linq collection with unit test
- How to extract the most common YEAR from an array of DateTime objects using LINQ
- Find Min and Max value in table between given variable in C#
- Trouble querying a collection of a collection
- EntityFramework calling scaler function throws Must declare the scalar variable
- Convert object collection to dictionary using LINQ
- Multiple rows update without select
- Flatten a collection based on an internal property