Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the order of EF linq query clauses influence performance?

Should I worry about the order of Entity Framework linq query clauses in terms of performance?

In the example below could changing the order of the two where clauses have an performance impact on the DB lookup?

        using (var context = new ModelContext())
        {
            var fetchedImages = (from images in context.Images.Include("ImageSource")
                                 where images.Type.Equals("jpg")
                                 where images.ImageSource.Id == 5
                                 select images).ToArray();
        }
like image 820
mola Avatar asked Oct 21 '22 14:10

mola


1 Answers

No, changing of these two where clauses will not affect performance. Generated SQL will look like this anyway:

WHERE [condition1] AND [condition2]

Besides, you can write conditions, combined with logical operators:

where images.Type.Equals("jpg") && images.ImageSource.Id == 5
like image 102
Dennis Avatar answered Oct 24 '22 11:10

Dennis