Entity Framework 4 Code First,复杂的多对多关系
我在 EF 中看到了几个使用代码优先的多对多关系的示例,但我遇到了一种不确定如何解决的情况。
我的应用程序有三个 POCO 类:帐户、用户和角色。每个用户都可以是多个帐户的成员,并且每个帐户都有一个独特的角色。例如,用户 A 可以属于帐户 A 的角色 A 和帐户 B 的角色 B。本质上,帐户和用户之间存在多对多关系,并且每个这些关系还具有分配给每个帐户的角色 -用户组合。
在我当前的非代码优先设置中。我有一个表,其中包含用户 ID、帐户 ID 和角色 ID。
有没有办法使用代码优先来做到这一点?
I've seen several examples of many to many relationships in EF using code-first, but I've run into a situation that I'm not sure how to solve.
My app has three POCO classes, Account, User and Role. Every user can be a member of multiple accounts and has a unique role for each one. For example, User A can be in Role A for Account A and Role B for Account B. Essentially, there is a many to many relationship between accounts and users, and each of these relationships also has a role that is assigned to each account-user combination.
In my current, non code-first setup. I have a table that has a user id, account id and role id.
Is there a way to do this using code-first?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以使用 CodeFirst 执行此操作,您将需要一个额外的类(实体)来表示此关系表。
您的用户将拥有一组具有角色和帐户的帐户成员资格。
yes you can do this with CodeFirst you will need an extra class (entity) to represent this relationship table.
where your user will have a collection of account memberships which have a role and an account.