0
我已經擴展名爲FirstName,姓氏的ApplicationUser類,但是當我創建遷移和數據庫時,新屬性不顯示。有什麼想法嗎?擴展應用程序用戶不傳播到表格模式
我ApplicationUser
類:
public class ApplicationUser : IdentityUser<int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>, IUser<int>
{
//extend with additional properties here
public string FirstName;
public string LastName;
public string GetFullName()
{
return FirstName + " " + LastName;
}
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser, int> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
}
我AppDbContext
:
public class AppDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public AppDbContext()
: base(ConfigurationSetting.DatabaseConnectionName)
{
}
public DbSet<ConfigurationSetting> ConfigurationSettings { get; set; }
public DbSet<Place> Places { get; set; }
public DbSet<CloudFiles.CloudFile> CloudFiles { get; set; }
public static AppDbContext Create()
{
return new AppDbContext();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>().ToTable("Users");
modelBuilder.Entity<ApplicationRole>().ToTable("Roles");
modelBuilder.Entity<ApplicationUserRole>().ToTable("UserRoles");
modelBuilder.Entity<ApplicationUserLogin>().ToTable("UserLogins");
modelBuilder.Entity<ApplicationUserClaim>().ToTable("UserClaims");
}
public bool InitializeDatabase()
{
try
{
Database.SetInitializer<AppDbContext>(new ApplicationDbInitializer());
}
catch
{
return false;
}
return true;
}
}
這是當我創建了一個遷移(只提供遷移代碼的一部分)什麼是創建:
CreateTable(
"dbo.Users",
c => new
{
Id = c.Int(nullable: false, identity: true),
Email = c.String(maxLength: 256),
EmailConfirmed = c.Boolean(nullable: false),
PasswordHash = c.String(),
SecurityStamp = c.String(),
PhoneNumber = c.String(),
PhoneNumberConfirmed = c.Boolean(nullable: false),
TwoFactorEnabled = c.Boolean(nullable: false),
LockoutEndDateUtc = c.DateTime(),
LockoutEnabled = c.Boolean(nullable: false),
AccessFailedCount = c.Int(nullable: false),
UserName = c.String(nullable: false, maxLength: 256),
})
.PrimaryKey(t => t.Id)
.Index(t => t.UserName, unique: true, name: "UserNameIndex");
你試過這些屬性的[NotMapped]屬性了嗎?它不會將它們映射到數據庫 – alexo 2014-12-04 21:04:48
@alexo但我希望這些屬性出現在數據庫中以存儲值。 – FrankO 2014-12-04 21:06:49
aaa,他們沒有出現,我以爲你需要他們那樣。以及你聲明變量,而不是屬性。嘗試使它們屬性,它應該工作 – alexo 2014-12-04 21:08:15