【问题标题】:What's the difference between property Entity Reference and property in Entity Data Model?实体数据模型中的属性实体引用和属性有什么区别?
【发布时间】:2011-08-02 22:54:46
【问题描述】:

我有如下三个表结构

AppUser             User                App              
*********           ******              ******
AppUserId           UserId              AppId
UserId
AppId 

表 AppUser 的 UserId 和 AppId 是表 User 和 App 的外键。当我为实体数据模型生成 3 个表时,它具有三个类 AppUser、User 以及 App。但是,我不了解 AppUser.UserReference 和 AppUser.User

【问题讨论】:

    标签: c# entity-framework entity-relationship ado.net-entity-data-model


    【解决方案1】:

    AppUser.User 是 User 类型的导航属性,AppUser.UserReference 是类型 EntityReference<User> 。它们是完全不同的对象。

    您可以使用 AppUser.User 访问相关用户属性或更改相关用户。 您可以使用 AppUser.UserReference,例如通过EntityReference<T>.Load() 方法加载相关用户。

    实际上 AppUser.UserReference.Value 等于 AppUser.User。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 2012-02-03
      • 1970-01-01
      • 1970-01-01
      • 2015-09-10
      • 2014-11-26
      相关资源
      最近更新 更多