简体   繁体   English

默认情况下,LINQ和Entity Framework加载的渴望程度如何?

[英]How eager does LINQ and Entity Framework load by default?

I'm new to LINQ and the Entity Framework. 我是LINQ和Entity Framework的新手。 I've been fetching collections from the database using the following: 我一直在使用以下方法从数据库中获取集合:

var Publications = from pubs in db.RecurringPublications
                   select pubs;

The Publications table is linked to other tables via foreign keys. Publications表通过外键链接到其他表。 I've been using this to reference properties like this: 我一直在使用它来引用这样的属性:

Publications.Single().LinkedTable.LinkedTableColumn

and sometimes even further down the chain: 有时甚至更进一步:

Publications.Single().LinkedTable.LinkedTable.LinkedLinkedTableColumn

I know you can specify lazy loading or eager loading, I was wondering how it's handled by default. 我知道您可以指定延迟加载或快速加载,我想知道默认情况下如何处理它。 Is there a maximum depth by default? 默认情况下是否有最大深度? Does it figure out how many joins to use at compile time? 它能计算出在编译时要使用多少个联接吗?

It's only going to eager load what's in that specific table. 它只是渴望加载该特定表中的内容。

var Publications = from pubs in db.RecurringPublications
                   select pubs;

Will only get the data from your RecurringPublications table. 仅从您的RecurringPublications表中获取数据。 You can specify if you want to load additional properties, but if you don't specify anything, it will only give you exactly what you ask for - nothing more. 您可以指定是否要加载其他属性,但如果不指定任何内容,则只会提供您所要的内容,仅此而已。

Publications.Single().LinkedTable.LinkedTableColumn

Is lazy loading your LinkedTableColumn - now if your return is Queryable (and it is so far), it's going to do a join and return a single SQL query. 懒惰地加载LinkedTableColumn-现在,如果您的返回值是可查询的(到目前为止),它将进行连接并返回单个SQL查询。

However, if the call has already been enumerated, it will make a second call. 但是,如果呼叫已被枚举,它将进行第二次呼叫。

Blog post to MSDN for info 向MSDN 发布博客以获取信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM