score:2
The problem here isn't with what LINQ is actually doing. The query for scenario 2 would just create something similar to:
SELECT * FROM
PERSON
WHERE Department = N'Development'
AND Gender = N'Male'
AND Role = N'Manager'
You need to run this against the database directly to figure out what's your performance bottleneck. You're most likely missing indexes and therefore forcing your database server to scan the entire table to get the result set back.
If you're using SQL Server, try running a profiler to determine the exact query that (assuming) LINQ-to-EF is generating and tune that.
score:-2
You need to optimize your DB, take a look on index
You can also do the same request with Specification pattern
public class NamedPersonSpecification : AbstractSpecification<Person>
{
private string _name;
public NamedPersonSpecification(string name)
{
this._name= name;
}
public override bool IsSatisfiedBy(Person o)
{
return o.Name.Equals(_name);
}
}
And Query like this:
IQueryable<T>.Where(specification.IsSatisfiedBy)
The advantage is to be more clear to request your LINQ
Source: stackoverflow.com
Related Articles
- How to construct efficient queries in C# LINQ to filter data
- c# Linq or code to extract groups from a single list of source data
- Proper way to construct linq queries to achieve fastest performance?
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Filter data between two dates using LINQ
- How does linq actually execute the code to retrieve data from the data source?
- LINQ Source Code Available
- How to create an efficient data structure for two-dimensional LINQ operations?
- Merge duplicate data without affecting others in LINQ code
- Use a linq query as microsoft local report Data Source (WinForms)
- Most efficient collection for storing data from LINQ to Entities?
- At what point is a LINQ data source determined?
- Efficient and proper Linq queries from database
- Is a full list returned first and then filtered when using linq to sql to filter data from a database or just the filtered list?
- creating Linq to sqlite dbml from DbLinq source code
- Does LINQ convert code to SQL queries
- Filter data in dataset using LINQ and get result as list of strings
- read icollection data using LINQ in C# code
- Is there a better or more efficient way to filter with linq
- Linq to sql as object data source - designer problem with partial classes
- C# LINQ How to get a data source from a db?
- Using LINQ query result for data source for GridControl c#
- How to filter distinct data using linq
- C# LINQ - Filter Queries
- How to swap the data source associated with a Linq query?
- Linq - pulling data from two tables - efficiency - alternative linq queries
- Filter data quarterly using LinQ
- How to filter data using Linq in List<object>
- Filter IEnumerable Data using Linq on ASP.NET Web API 2
- How to filter related data using Entity Framework and LINQ to SQL and LinqKit PredicateBuilder Or IdeaBlade DevForce
- Linq query involving 4 joined tables, to a many to many table
- c# linq join on a sublist in a list
- C# Full text search with Linq
- Fill in property in list from another list by joining them
- is it possible to have a conditional field in an anonymous type
- LINQ Filter values on list values using contain
- Null Values in Entity Framework
- SingleOrDefault, how to write out default?
- joining list of strings
- Cannot Use LINQ-Method In Razor View ASP.Net
- LINQ to SQL not getting correct data
- Can I get values from my database using this method but without generating the additional text?
- Per Invoice show string/int array of unique products
- How to group IList<T> using LINQ?
- Linq query to get the last record
- Query for string containing one or more of many strings
- Linq Get next n records
- Insert multiple rows to a table with 1 hit to the database
- Convert to IEnumerable<DateTime> result of LINQ Query
- Linq2SQL dealing with inserts/deletes on table with unique constraints