自动生成的实体类中缺少导航属性

发布于 2024-10-17 05:22:36 字数 754 浏览 0 评论 0原文

我正在实体框架 4.0 中迈出第一步,目前面临一个恼人的问题。

我的应用程序的身份验证/授权过程基于标准的 ASP.NET 成员资格提供程序,换句话说,数据库是众所周知的 ASPNETDB.MDF。在此数据库中,除其他外,还有表 aspnet_Users 和 aspnet_Roles,它们通过表 aspnet_UsersInRoles 链接在一起。

我生成了一个新的“ADO.NET 实体数据模型”,选择了“从数据库生成”,提供了所有必要的参数,向导为我生成了相关的 .EDMX 文件。我将此命名为“SecurityModel”。在 aspnet_User 实体中,我可以看到有一个导航属性应该检索所有链接的角色,反之亦然。

此时,我添加了一个新的“域服务”,在我的例子中为 SecurityDomainService。 当我被问到时,我选择了 SecurityModel 及其包含的所有表。 即使在这种情况下,向导也会为我生成 SecurityDomainService。

显然完全没有问题。但是,我意识到在实体 aspnet_User 中,我拥有除角色之外的所有导航属性(成员资格、个人资料、应用程序等)。

我在某处读到 EntityFramework 不处理多对多关系。但是,我可以在实体数据模型中看到 aspnet_Roles 和 aspnet_Users 之间存在关联,并且它基于 aspnet_UsersInRoles。我还可以在数据模型设计器中看到用户实体中的“角色”导航属性。

所以,我的问题是为什么这个导航属性没有生成?

预先感谢您的所有帮助。 干杯, G。

I am moving my first steps in the Entity Framework 4.0, and I am currently facing an annoying issue.

The authentication/authorization process of my application is based on the standard ASP.NET membership provider, in other words the database is the well-known ASPNETDB.MDF. In this database there are - amongst others - the tables aspnet_Users and aspnet_Roles, which are linked together by the table aspnet_UsersInRoles.

I generated a new "ADO.NET Entity Data Model", I selected Generate from Database, I provided all the necessary parameters, and the wizard generated for me the relative .EDMX file. I named this "SecurityModel". In the aspnet_User entity I can see there is a navigation property that should retrieve all linked Roles, and viceversa.

At this point I added a new "Domain Service", in my case SecurityDomainService.
When I was asked, I selected the SecurityModel, and all the tables it contains.
Even in this case the wizard generated the SecurityDomainService for me.

Apparently no problems at all. However, I realized that in the entity aspnet_User I have all navigation properties (Membership, Profile, Applications, etc.) but Roles.

I read somewhere that EntityFramework doesnt handle many-to-many relationships. However I can see in my Entity Data Model that an Association exists between aspnet_Roles and aspnet_Users, and it is based on aspnet_UsersInRoles. I can also see in the Data Model designer the "Roles" navigation property in the User entity.

So, my question is why has not this navigation property been generated?

Thanks in advance for all your help.
Cheers,
G.

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

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

发布评论

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

评论(1

绅士风度i 2024-10-24 05:22:36

这里的问题是 aspnet_UsersInRoles 表仅包含多对多关系中表的主键字段。实体框架“内联”此表并且不将其表示为实体。实体框架可以很好地处理这个问题——RIA 服务不支持这种类型的关系。

只需向表中添加一个额外字段即可阻止其内联并导致生成 aspnet_UsersInRoles。这将在 RIA 服务中得到支持。

您需要小心修改 aspnet 架构,以确保不会破坏任何存储过程等,但添加可为空位列不应造成太多破坏。

The problem here is that the aspnet_UsersInRoles table contains only the primary key fields of the tables in the many to many relationship. Entity Framework 'inlines' this table and does not represent it as an entity. Entity Framework handles this fine - it is RIA services that does not support this type of relationship.

Simply adding one extra field to the table will prevent it from being inlined and result in an aspnet_UsersInRoles being generated. This will be supported within RIA Services.

You will need to be careful modifying the aspnet schema to ensure that you do not break any of the stored procedures etc but the addition of a nullable bit column should not cause too much disruption.

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