部署codefirst不会创建所有表字段

时间:2013-06-11 02:08:18

标签: entity-framework c#-4.0 asp.net-mvc-4 ef-code-first

我在尝试将代码首先基于mvc4应用程序部署到azure时遇到了一些问题。

在创建localdb时可以正常工作但是在尝试部署到只有UserProfile表时才会使用Username& UserId字段已创建。

我的模型看起来像

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }

    public Guid ConsumerId { get; set; }
    public string UserName { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
    public bool IsMale { get; set; }
    public string Mobile { get; set; }
    [DefaultValue(false)]
    public bool IsSmsVerified { get; set; }
    public string SmsVerificationCode { get; set; }

}

上下文

  public class UsersContext : DbContext
{
    public UsersContext()
        : base("DefaultConnection")
    {
    }

    public DbSet<UserProfile> UserProfiles { get; set; }
    public DbSet<ExternalUserInformation> ExternalUsers { get; set; }
}

配置

 internal sealed class Configuration : DbMigrationsConfiguration<Web.Models.UsersContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }

    protected override void Seed(Web.Models.UsersContext context)
    {
        //  This method will be called after migrating to the latest version.

        //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
        //  to avoid creating duplicate seed data. E.g.
        //
        //    context.People.AddOrUpdate(
        //      p => p.FullName,
        //      new Person { FullName = "Andrew Peters" },
        //      new Person { FullName = "Brice Lambson" },
        //      new Person { FullName = "Rowan Miller" }
        //    );
        //

        WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

我需要打开一个神奇的开关吗?

0 个答案:

没有答案