实体框架4.1默认加载 [英] Entity Framework 4.1 default eager loading

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

问题描述

我正在使用Entity Framework 4.1代码第一种方法。

I'm using Entity Framework 4.1 code first approach.

我想要加载作为我的dafault配置,并避免使用Include扩展方法在每个提取查询中。

I want to make eager loading as my the dafault configuration, and by that avoid using the Include extension method in each fetching query.

我在MSDN中做了推荐,在DbContext构造函数中更改了简单的惰性属性:

I did as recomended in MSDN, changing the simple lazy property at the DbContext constructor:

public class EMarketContext : DbContext
{
    public EMarketContext()
    {
        // Change the default lazy loading to eager loading
        this.Configuration.LazyLoadingEnabled = false; 
    }
}

不幸的是,这种方法不起作用。我必须使用Include方法在每个查询中执行热心加载。任何想法为什么?
提前感谢

unfortunately, this approach is not working. I have to use the Include method to perform eager loading in each query. Any ideas why? Thanks in advance.

推荐答案

没有默认的加载加载配置。您必须始终定义 Include 或创建一些可重用的方法,将包装添加包含。例如,您可以在上下文中放置类似的方法:

There is no default configuration for eager loading. You must always define Include or create some reusable method which will wrap adding include. For example you can place similar method to your context:

public IQueryable<MyEntity> GetMyEntities()
{
    return this.MyEntities.Include(e => e.SomeOtherEntities);
}

这篇关于实体框架4.1默认加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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