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

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.


Related Query

More Query from same tag