EF4 自跟踪实体导航属性

发布于 2024-10-10 03:55:48 字数 421 浏览 0 评论 0原文

我正在使用 EF4 和自我跟踪实体 T4 模板。

当我在实体页面(带有导航属性类别)上执行选择时,如下所示:

var page = (from p in context.Page select p).FirstOrDefault();

导航属性类别始终为空。

当我这样做时:

var page = (from p in context.Page.Include("Category") select p).FirstOrDefault();

类别已加载。

为什么必须将 include 函数与硬编码字符串一起使用?当我访问 EF4 时,是否无法自动加载导航属性?

或者这只适用于 EntityObjects 而不适用于 STE?

I'm using EF4 with Self Tracking Entities T4 template.

When I perform a select on entity Page (with navigation property Category) like:

var page = (from p in context.Page select p).FirstOrDefault();

The navigation property Category is always null.

When I do it like this:

var page = (from p in context.Page.Include("Category") select p).FirstOrDefault();

The Category is loaded.

Why do I have to use the include function with a hardcoded string? Is it not possible to have EF4 automatically load the navigation property when I access it?

Or does that only work with EntityObjects and not STE?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜光 2024-10-17 03:55:48

STE不支持延迟加载,只能通过context.LoadProperty。 POCO + EntityObject 确实支持它。

.include 用于急切加载,希望该方法能够更改为支持 lambda 表达式而不是硬编码字符串。

STE does not support lazy loading, only through context.LoadProperty. POCO + EntityObject do support it.

.Include is for eager loading, hopefully this method will be changed to support lambda expressions instead of hardcoded string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文