带有 EF 的 ASP.NET MVC 3 无法识别多对多联接表
在我的数据库中,我有一个用户表,然后是另一个包含角色之类的表。他们之间有一个多对多的连接表。当某人创建新用户时,他们必须能够为该用户选择他们想要的角色。但是 EF 不允许我将我的用户与另一个表关联起来。我有一个下拉列表,但是当选择角色时,出现无效输入错误,指出 PKID 不是正确的输入。 我肯定遗漏了 EF 的工作原理,或者至少是它如何链接到 MVC 3
In my database I have a User table and then another table with something like roles. There is a many to many join table between them. When someone is making a new user they have to be able to select the role they want for the user. However EF is not letting me associate my user with this other table. I had a dropdown list, but when the role was selected an invalid enrty error came up saying the PKID was not the correct input.
I must be missing something in how EF works, or at least how it links to MVC 3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,当您具有多对多关系时,您需要一个单独的表来保存两个外键。
所以你可能会想:
为什么这里需要多对多关系?如果我是你,我会创建类似的东西,
这样用户就可以拥有角色,并且在你的代码中你可以执行类似的操作:
或者
Generally speaking, when you have a many to many relationship you need a separate table to hold the two foreign keys.
So you might have:
Why do you need a many to many relationship here? If I were you I'd create something like
That way a user can have a role, and in your code you can do something like:
Or