【发布时间】:2016-05-19 14:40:23
【问题描述】:
我已经启动了一个由 Azure 托管的新项目 - 我正在尝试让它自动创建表。
我有一个模型:
public class Account
{
[Key]
[Required]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Surname { get; set; }
[Required]
[EmailAddress]
public string Email { get; set; }
}
在我的 Global.asax 中:
Database.SetInitializer(new CreateDatabaseIfNotExists<ApplicationDbContext>());
最后是 ApplicationDbContext:
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public System.Data.Entity.DbSet<Account> Accounts { get; set; }
}
运行我的项目后,它不会创建表。还是我做错了什么我没有看到?
【问题讨论】:
-
您好,Kevin,您的
DefaultConnection连接字符串正确吗?
标签: c# entity-framework visual-studio