实体框架的引用不会自动加载 [英] Entity Framework references not loading automatically

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

问题描述

在ADO.Net Entity Framework的,我有一个对象,它有4个其他对象的引用。出于某种原因,当我查询这些引用,其中两个自动加载(如预期),以及他们两个总是返回null。

In the ADO.Net Entity Framework, I have an object which has 4 references to other objects. For some reason, when I query those references, two of them load automatically (as expected), and two of them always return null.

奇怪的是,当我的手动的要求引用加载,加载它们只是花花公子。

Bizarrely enough, when I manually ask the references to load, they load just dandy.

作为一个例子:

if (account.HoldingEntity == null && 
    account.HoldingEntityReference.EntityKey != null) {

    account.HoldingEntityReference.Load();
    account.HoldingEntity = account.HoldingEntityReference.Value;
}

当我第一次检查 HoldingEntity 它总是空,但负载将返回HoldingEntity没有问题。

When I first check the HoldingEntity it is always null, however the Load will return the HoldingEntity without problem.

任何线索?

谢谢!

推荐答案

使用ADO.NET实体时,需要指定要与自动加载包含哪些实体,在

Using ADO.NET Entities, you need to specify what entities you want to load automatically with Include, as in

Dim entity = (From e in db.Entities.Include("SubEntity"))

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

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