webpages_UsersInRoles失踪 [英] webpages_UsersInRoles missing
问题描述
我使用ASP.NET MVC 4连同SimpleMemmbership。
I am using ASP.NET MVC 4 together with SimpleMemmbership.
当我建我的应用程序下表是自动建立
When I built my application the following tables were built automatically
webpages_Membership
webpages_Membership
webpages_OAuthMembership
webpages_OAuthMembership
webpages_Roles
webpages_Roles
我可以成功注册的用户。
I can successfully register users.
然而,在 webpages_UsersInRoles 表似乎缺少。
有谁知道为什么这个表丢失?
Does anyone know why this table is missing?
推荐答案
<一个href=\"http://blog.spontaneouspublicity.com/including-asp-net-simple-membership-tables-as-part-of-your-entity-framework-model\">This文章,可能会帮助您解决您的问题。
This article might assist you in resolving your issue.
更新:
上面的文章让我们在正确的方向前进。我们的解决方案是增加一个定义webpages_UsersInRoles我们UserProfile.cs类被初始化期间使用(我们正在做的code在前)。
The article above got us going in the right direction. Our solution was to add a definition for "webpages_UsersInRoles to our UserProfile.cs class that gets used during initialization (we are doing code first).
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
[DataType(DataType.EmailAddress)]
public string EmailAddress { get; set; }
public bool IsEnabled { get; set; }
}
[Table("webpages_Membership")]
public class Membership
{
public Membership()
{
//Roles = new List<Role>();
OAuthMemberships = new List<OAuthMembership>();
UsersInRoles = new List<UsersInRole>();
}
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public int UserId { get; set; }
public DateTime? CreateDate { get; set; }
[StringLength(128)]
public string ConfirmationToken { get; set; }
public bool? IsConfirmed { get; set; }
public DateTime? LastPasswordFailureDate { get; set; }
public int PasswordFailuresSinceLastSuccess { get; set; }
[Required, StringLength(128)]
public string Password { get; set; }
public DateTime? PasswordChangedDate { get; set; }
[Required, StringLength(128)]
public string PasswordSalt { get; set; }
[StringLength(128)]
public string PasswordVerificationToken { get; set; }
public DateTime? PasswordVerificationTokenExpirationDate { get; set; }
//public ICollection<Role> Roles { get; set; }
[ForeignKey("UserId")]
public ICollection<OAuthMembership> OAuthMemberships { get; set; }
[ForeignKey("UserId")]
public ICollection<UsersInRole> UsersInRoles { get; set; }
}
[Table("webpages_OAuthMembership")]
public class OAuthMembership
{
[Key, Column(Order = 0), StringLength(30)]
public string Provider { get; set; }
[Key, Column(Order = 1), StringLength(100)]
public string ProviderUserId { get; set; }
public int UserId { get; set; }
[Column("UserId"), InverseProperty("OAuthMemberships")]
public Membership User { get; set; }
}
[Table("webpages_UsersInRoles")]
public class UsersInRole
{
[Key, Column(Order = 0)]
public int RoleId { get; set; }
[Key, Column(Order = 1)]
public int UserId { get; set; }
[Column("RoleId"), InverseProperty("UsersInRoles")]
public Role Roles { get; set; }
[Column("UserId"), InverseProperty("UsersInRoles")]
public Membership Members { get; set; }
}
[Table("webpages_Roles")]
public class Role
{
public Role()
{
UsersInRoles = new List<UsersInRole>();
}
[Key]
public int RoleId { get; set; }
[StringLength(256)]
public string RoleName { get; set; }
//public ICollection<Membership> Members { get; set; }
[ForeignKey("RoleId")]
public ICollection<UsersInRole> UsersInRoles { get; set; }
}
然后在继承的DbContext类,我们添加了公共DbSet UsersInRoles {搞定;组; }
Then on the class that inherits dbContext we added the public DbSet UsersInRoles { get; set; }.
public class IntranetEntities : DbContext
{
public DbSet<UserProfile> UserProfiles { get; set; }
public DbSet<Membership> Memberships { get; set; }
public DbSet<Role> Roles { get; set; }
public DbSet<UsersInRole> UsersInRoles { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
public override int SaveChanges()
{
try
{
return base.SaveChanges();
}
catch (DbEntityValidationException dbEx)
{
foreach (var validationErrors in dbEx.EntityValidationErrors)
{
foreach (var validationError in validationErrors.ValidationErrors)
{
Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
}
}
}
return 0;
}
}
我们着手建立我们的项目,我们利用执行VS包管理器控制台(因为我们正在做的code首先开发)
We then proceeded to build our project and using the VS package manager console we executed (since we are doing code first development)
更新数据库-verbose
update-database -verbose
该模型然后更新到了我们的预期。我已经提供了所有必需的code在希望这样可以节省有人在未来的时间和悲痛。
The model was then updated to our expectations. I have provided all the required code in the hopes it saves someone in the future time and grief.
这篇关于webpages_UsersInRoles失踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!