Entity framework IsInRole-错误无效列名';用户ID';
这是一个使用SimpleMembership和EntityFramework优先方法的MVC4项目。 当我尝试使用User.IsInRole(“Admin”)时,我遇到2个错误 1。列名“UserId”无效。Entity framework IsInRole-错误无效列名';用户ID';,entity-framework,asp.net-mvc-4,simplemembership,Entity Framework,Asp.net Mvc 4,Simplemembership,这是一个使用SimpleMembership和EntityFramework优先方法的MVC4项目。 当我尝试使用User.IsInRole(“Admin”)时,我遇到2个错误 1。列名“UserId”无效。 2.列名“RoleId”无效。 我怀疑原因是因为我定义了一个用户类和相应的表,其中主键字段被称为“Id”,而不是“UserId”(这是MVC4模板中的默认值)。这个项目即将完成,所以我不想恢复使用UserId,除非我真的必须这样做 public class User { publi
2.列名“RoleId”无效。 我怀疑原因是因为我定义了一个用户类和相应的表,其中主键字段被称为“Id”,而不是“UserId”(这是MVC4模板中的默认值)。这个项目即将完成,所以我不想恢复使用UserId,除非我真的必须这样做
public class User
{
public long Id { get; set; }
public string UserName { get; set; }
public string FullName { get; set; }
public string Email { get; set; }
public string Intro { get; set; }
public string Locale { get; set; }
}
其他简单成员资格表上的主键列是默认值,如下所示
Users : Id
webpages_Membership : UserId
webpages_UsersInRoles : Users_Id
webpages_Roles : RoleId
所有其他会员资格功能目前都可以正常工作。即登录、注册、OAuth登录等
如果有人能解释这件事的话,请照我现在的样子做
感谢您调用WebSecurity.InitializeDatabaseConnection,您是否将参数userIdColumn修改为等于“Id”?webpages\u UsersInRoles的默认值是“UserId”,而不是“User\u Id”,并且应该有一个“RoleId”列。User.IsInRole来自哪里?这是你写的方法吗?为什么不使用SimpleRoleProvider.IsUserInRole?是的,我在网页上有一列RoleID\u UsersInRoles,但我也有一列Users\u Id。。我试试看会发生什么。我正在使用默认的IPrincipal方法User.IsInRole,是否有其他方法获取此信息?