实体框架SQL查询执行 [英] Entity Framework SQL Query Execution

查看:99
本文介绍了实体框架SQL查询执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用实体框架,当一个执行查询时,可以说2000个需要群组和其他计算的记录,查询是否在服务器上执行,只有结果发送到客户端或全部发送到客户端然后执行?

Using the Entity Framework, when one executes a query on lets say 2000 records requiring a groupby and some other calculations, does the query get executed on the server and only the results sent over to the client or is it all sent over to the client and then executed?

这使用SQL Server。

This using SQL Server.

我正在寻找这个,因为我要开始一个项目,在一个巨大的数据库中将需要大量查询,并且想知道如果使用实体框架,这将在网络上产生很大的负载。

I'm looking into this, as I'm going to be starting a project where there will be loads of queries required on a huge database and want to know if this will produce a significant load on the network, if using the Entity Framework.

推荐答案

我会认为所有的数据库查询都是在服务器端(数据库所在的地方)完成的,结果被传递。然而,在Linq你有一个所谓的延迟执行(延迟加载),所以您的信息实际上不会被检索,直到您尝试访问它,例如调用ToList()或访问属性(相关表)。

I would think all database querying is done on the server side (where the database is!) and the results are passed over. However, in Linq you have what's known as Delayed Execution (lazily loaded) so your information isn't actually retrieved until you try to access it e.g. calling ToList() or accessing a property (related table).

您可以选择使用 LoadWith 如果需要加载,

You have the option to use the LoadWith to do eager loading if you require it.

所以在性能方面,如果你真的只想做一次旅行到你的查询的数据库(有相关的表),我建议使用 LoadWith 选项。但是,它确实取决于具体情况。

So in terms of performance if you only really want to make 1 trip to the Database for your query (which has related tables) I would advise using the LoadWith options. However, it does really depend on the particular situation.

这篇关于实体框架SQL查询执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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