mol*_*ola 5 c# linq performance linq-to-entities entity-framework
我应该在性能方面担心实体框架linq查询子句的顺序吗?
在下面的示例中,可以更改两个where子句对数据库查找的性能影响的顺序吗?
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();
}
Run Code Online (Sandbox Code Playgroud)
不会,更改这两个where
条款不会影响性能。无论如何,生成的 SQL 看起来像这样:
WHERE [condition1] AND [condition2]
Run Code Online (Sandbox Code Playgroud)
此外,您可以编写条件,结合逻辑运算符:
where images.Type.Equals("jpg") && images.ImageSource.Id == 5
Run Code Online (Sandbox Code Playgroud)