MVC4实体框架和Simplemembership重新创建

时间:2013-07-30 19:24:43

标签: asp.net-mvc entity-framework simplemembership

好的,我正在加入Simplemembership。

  

模型UsersProfiles

namespace OilNGasWeb.Models
{
[Table("Users")]
public class UserProfiles
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }

    public string UserName { get; set; }

    public string FirstName { get; set; }

    public string LastName { get; set; }

    public string MiddleName { get; set; }

    public string Initials { get; set; }

    public string Company { get; set; }

    public string Department { get; set; }

    public string Title { get; set; }

    public string Team { get; set; }

    public string TeamSub { get; set; }

    public string Phone { get; set; }

    public string ImageLocation { get; set; }

    public string CurrentlyAuthorized { get; set; }

    public string Note { get; set; }

    public string Comment { get; set; }

    //public virtual dbClient Client { get; set; }

    public virtual ICollection<Roles> Roles { get; set; } //many to many
    public virtual ICollection<dbClient> Clients { get; set; } // many to many

}
}
  

角色

namespace OilNGasWeb.Models
{
[Table("webpages_Roles")]
public class Roles
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    [Required(ErrorMessage = "Required")]
    public int RoleID { get; set; }
    [Required(ErrorMessage = "Required")]
    public string RoleName { get; set; }

    public virtual ICollection<UserProfiles> UserProfiles { get; set; } //many to many

}
}

我现在的问题是我创建了多对多的表,就像我在修改之前看到的那样创建我的问题是如何让这些表重命名

webpages_UsersInRoles

我宁愿不进入SSMS并在物理上更改它们而不是告诉MVC使用不同的实例

从上面的代码中生成的 RolesUserProfiles 而不是webpages_UsersInRoles

错误显示程序何时尝试@if(User.IsInRole(“Administrator”))验证用户。

当然,我在 IsInRole 上点击了F12,带我进入定义....

确实如此,但那里全是空的

现在怎样?如果它隐藏起来,我怎么能重新编码呢?代码在哪里,以及如何修改它?

我想要的是

  1. 在创建表 ManytoMany 时重命名
  2. 能够修改寻找webpages_UsersInRoles
  3. 的代码

    提前致谢。

1 个答案:

答案 0 :(得分:1)

您无法重命名表格。表名在SimpleMembership中进行了硬编码。你可以在这里看到源代码:

http://aspnetwebstack.codeplex.com/SourceControl/latest#src/WebMatrix.WebData/SimpleMembershipProvider.cs

不要使用EF导航属性。您应该通过Membership或WebSecurity API来访问此信息。

如果你真的想这样做,那么你需要配置EF以使用简单成员资格所需的表名,这意味着使用流畅的映射语法......这不是很直观。

相关问题