Linq to SQL:选择优化 [英] Linq to SQL: select optimization

查看:61
本文介绍了Linq to SQL:选择优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MSSQL中的大表上;选择特定的列可以提高查询速度.同样适用于Linq to SQL吗?

On large tables in MSSQL; selecting specific columns results in greater speed of the query. Does the same apply to Linq to SQL?

这会吗:

var person = from p in [DataContextObject].Persons
             where p.PersonsID == 1
             select new { p.PersonsID, p.PersonsAdress, p.PersonsZipcode };

比这快:

var person = from p in [DataContextObject].Persons
             where p.PersonsID == 1
             select p;

...?

推荐答案

我强烈推荐 LinqPad .它是免费的,可让您动态运行LINQ查询.您还可以查看生成的SQL.

I highly recommend LinqPad. It is free and lets you run LINQ queries dynamically. When you can also look at the SQL that is generated.

您将看到LINQ查询会将第一个查询转换为仅选择那些列.所以它更快.

What you will see is that the LINQ query will translate the first query into selecting only those columns. So it is faster.

这篇关于Linq to SQL:选择优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆