简体   繁体   English

实体框架多对多关系

[英]Entity Framework Many To Many Relationship

I'm using the default ASP.NET profile and membership provider. 我正在使用默认的ASP.NET配置文件和成员资格提供程序。 I want to create a ASP List View with the name of the user and their role. 我想用用户名及其角色创建一个ASP列表视图。 When I try using this functionality I get a error: 当我尝试使用此功能时,出现错误:

Code behind: 代码背后:

public List<aspnet_Users> GetUsers(int startRowIndex, int maximumRows)
{
    this.entities.aspnet_Users.Include("aspnet_Roles").OrderBy(u => u.UserId).Skip(startRowIndex).Take(maximumRows).ToList();
}

Page directive: 页面指​​令:

<%# Eval("aspnet_Roles.RoleName")%>

It's not working because it's a many to many relationship in the database. 它不起作用,因为它与数据库中的多对多关系有关。 How do I change my code behind method to map across the many to many relationship? 如何更改方法后面的代码以映射多对多关系?

Don't do this. 不要这样做。 You shouldn't map the membership table s. 您不应该映射成员资格表 The ASP.NET membership API already has a method to get a page of member data . ASP.NET成员资格API已经具有一种获取成员数据页面的方法 You're reinventing the wheel, and replacing it with a version where you can't change the tire. 您正在重新设计轮子,并用无法更换轮胎的版本替换它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM