【问题标题】:EF4 Self tracking entities navigation propertyEF4 自我跟踪实体导航属性
【发布时间】:2011-01-05 23:17:45
【问题描述】:

我正在使用带有自我跟踪实体 T4 模板的 EF4。

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

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

导航属性 Category 始终为 null。

当我这样做时:

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

类别已加载。

为什么我必须使用包含硬编码字符串的函数?当我访问它时,是否无法让 EF4 自动加载导航属性?

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

【问题讨论】:

    标签: c#-4.0 entity-framework-4 entity-relationship


    【解决方案1】:

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

    .Include 用于预加载,希望此方法将更改为支持 lambda 表达式而不是硬编码字符串。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多