的EntityFramework包括VS连接性能 [英] EntityFramework include vs join performance

查看:123
本文介绍了的EntityFramework包括VS连接性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,使用实体框架,其中一个产生更好的性能,当?

I'd like to know, when using entity framework, which one yields better performance?

我读过,如果你有你的entites之间的外交关系,它是preferred使用包括在加入。

I've read that if you have foreign relationships between your entites, it's preferred to use include over join.

如果我只是获取1行从2个不同的entites记录(含外键关系),这是否有所作为,如果我是用包括在加入?

If I'm just retrieving 1 row with records from 2 different entites (with foreign key relationship), does it make a difference if I were to use include over join?

有没有记录我取回来的金额影响加入,包括之间的性能?

Does the amount of records I'm fetching back affect the performance between join and include?

推荐答案

我会强烈建议你做一些的分析

I would highly recommend you to do some profiling.

有时预先加载( .INCLUDE )是好的,有时候不是;-) 只要有一个看起来生成的T-SQL的探查,你就会知道为什么!有一个在执行计划也是如此。

Sometimes eager loading (.Include) is good, sometimes not ;-) Just have a look a the generated T-SQL in the profiler and you'll know why! Have a look at the execution plans as well.

尝试 .INCLUDE 一些一到多的关系,在查询和查看的数据量将被检索:数据将由数量乘以在所有行包含表。大量的重复数据,可能会拉过电线导致高带宽消耗和性能问题。

Try to .Include some one-to-many relations in a query and look at the amount of data that will be retrieved: data will be multiplied by the number of rows in all included tables. A lot of duplicated data might be pulled over the wire causing high bandwith consumption and performance issue.

请记住,有时它甚至更好地执行相关数据的简单和快速的单独的查询(无延迟加载)。这可能是更有效的查询,假设客户,然后查询订单分开,让EF自动加入他们自己。

Remember that sometimes it's even better to perform simple and fast separate queries for related data (without lazy loading). It might be more efficient to query, let's say Customers and then query Orders separately and let EF join them itself automatically.

这是我自己的经验,具有很强的DBA团队在看所有的EF所产生的问题,我建议不要使用开发 .INCLUDE 了; - )

From my own experience, having a strong DBA team looking at all the queries generated by EF, I advised developers not using .Include anymore ;-)

这篇关于的EntityFramework包括VS连接性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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