Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ASP.NET MVC4中注册自定义用户配置文件会导致重复的表_Asp.net_Asp.net Mvc_Asp.net Mvc 4_Asp.net Membership - Fatal编程技术网

在ASP.NET MVC4中注册自定义用户配置文件会导致重复的表

在ASP.NET MVC4中注册自定义用户配置文件会导致重复的表,asp.net,asp.net-mvc,asp.net-mvc-4,asp.net-membership,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Asp.net Membership,我正在尝试在ASP.NET MVC4 Internet应用程序中存储自定义UserProfile类。UserProfile类名为“Usuario”,如下所示: [Table("Usuarios")] public class Usuario { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public str

我正在尝试在ASP.NET MVC4 Internet应用程序中存储自定义UserProfile类。UserProfile类名为“Usuario”,如下所示:

[Table("Usuarios")]
public class Usuario
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    public string UserName { get; set; }
    [EmailAddress]
    public string Correo { get; set; }
    public string Twitter { get; set; }
    public string Perfil { get; set; }
    public string LinkedIn { get; set; }
    public List<Evento> Ponencias { get; set; }
    public List<Evento> Asistencias { get; set; }
    public List<Evento> EventosCreados { get; set; }
}
 public class WeventioDb : DbContext
{
    public DbSet<Usuario> Usuarios { get; set; }
    public DbSet<Evento> Eventos { get; set; }
    public DbSet<Comentario> Comentarios { get; set; }
    public DbSet<Ubicacion> Ubicaciones { get; set; }
}
 public ActionResult Register(RegisterModel model)
    {
        if (ModelState.IsValid)
        {
            try
            {
                WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                WebSecurity.Login(model.UserName, model.Password);
                return RedirectToAction("Index", "Home");
            }
            catch (MembershipCreateUserException e)
            {
                ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
            }
        }

        return View(model);
    }
关于如何创建一个用户并将其存储到“Usuarios”表中并与成员一起使用,您有什么想法吗

Upadte:这是我的初始迁移(表创建)的样子,它正在创建正确的表“Usuarios”,但当我转到.mdf文件时,“Usuarios”表是空的,所有注册用户都在“Usuario”中,如前所述:

public partial class Initial : DbMigration
{
    public override void Up()
    {
        CreateTable(
            "dbo.Usuarios",
            c => new
                {
                    UserId = c.Int(nullable: false, identity: true),
                    UserName = c.String(),
                    Correo = c.String(),
                    Twitter = c.String(),
                    Perfil = c.String(),
                    LinkedIn = c.String(),
                    Evento_Id = c.Int(),
                    Evento_Id1 = c.Int(),
                })
            .PrimaryKey(t => t.UserId)
            .ForeignKey("dbo.Eventos", t => t.Evento_Id)
            .ForeignKey("dbo.Eventos", t => t.Evento_Id1)
            .Index(t => t.Evento_Id)
            .Index(t => t.Evento_Id1);

        CreateTable(
            "dbo.Eventos",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    Fecha = c.DateTime(nullable: false),
                    Precio = c.Double(nullable: false),
                    Descripcion = c.String(),
                    Schema = c.String(),
                    Sector = c.String(),
                    Banner = c.String(),
                    Imagen = c.String(),
                    Twitter = c.String(),
                    Hashtag = c.String(),
                    Programa = c.String(),
                    Organizador_UserId = c.Int(),
                    Rating_ID = c.Int(),
                    Sitio_Id = c.Int(),
                    Usuario_UserId = c.Int(),
                    Usuario_UserId1 = c.Int(),
                    Usuario_UserId2 = c.Int(),
                })
            .PrimaryKey(t => t.Id)
            .ForeignKey("dbo.Usuarios", t => t.Organizador_UserId)
            .ForeignKey("dbo.Ratings", t => t.Rating_ID)
            .ForeignKey("dbo.Ubicacions", t => t.Sitio_Id)
            .ForeignKey("dbo.Usuarios", t => t.Usuario_UserId)
            .ForeignKey("dbo.Usuarios", t => t.Usuario_UserId1)
            .ForeignKey("dbo.Usuarios", t => t.Usuario_UserId2)
            .Index(t => t.Organizador_UserId)
            .Index(t => t.Rating_ID)
            .Index(t => t.Sitio_Id)
            .Index(t => t.Usuario_UserId)
            .Index(t => t.Usuario_UserId1)
            .Index(t => t.Usuario_UserId2);

        CreateTable(
            "dbo.Ratings",
            c => new
                {
                    ID = c.Int(nullable: false, identity: true),
                    Texto = c.String(),
                    Puntaje = c.Int(nullable: false),
                    Fecha = c.DateTime(nullable: false),
                    Autor_UserId = c.Int(),
                })
            .PrimaryKey(t => t.ID)
            .ForeignKey("dbo.Usuarios", t => t.Autor_UserId)
            .Index(t => t.Autor_UserId);

        CreateTable(
            "dbo.Ubicacions",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    Latitud = c.Double(nullable: false),
                    Longitud = c.Double(nullable: false),
                    Direccion = c.String(),
                    Nombre = c.String(),
                    Twitter = c.String(),
                    CodigoPostal = c.Int(nullable: false),
                    Ciudad = c.String(),
                    Estado = c.String(),
                })
            .PrimaryKey(t => t.Id);

        CreateTable(
            "dbo.Comentarios",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    Texto = c.String(),
                    Fecha = c.DateTime(nullable: false),
                    Autor_UserId = c.Int(),
                    Evento_Id = c.Int(),
                })
            .PrimaryKey(t => t.Id)
            .ForeignKey("dbo.Usuarios", t => t.Autor_UserId)
            .ForeignKey("dbo.Eventos", t => t.Evento_Id)
            .Index(t => t.Autor_UserId)
            .Index(t => t.Evento_Id);

    }

    public override void Down()
    {
        DropIndex("dbo.Comentarios", new[] { "Evento_Id" });
        DropIndex("dbo.Comentarios", new[] { "Autor_UserId" });
        DropIndex("dbo.Ratings", new[] { "Autor_UserId" });
        DropIndex("dbo.Eventos", new[] { "Usuario_UserId2" });
        DropIndex("dbo.Eventos", new[] { "Usuario_UserId1" });
        DropIndex("dbo.Eventos", new[] { "Usuario_UserId" });
        DropIndex("dbo.Eventos", new[] { "Sitio_Id" });
        DropIndex("dbo.Eventos", new[] { "Rating_ID" });
        DropIndex("dbo.Eventos", new[] { "Organizador_UserId" });
        DropIndex("dbo.Usuarios", new[] { "Evento_Id1" });
        DropIndex("dbo.Usuarios", new[] { "Evento_Id" });
        DropForeignKey("dbo.Comentarios", "Evento_Id", "dbo.Eventos");
        DropForeignKey("dbo.Comentarios", "Autor_UserId", "dbo.Usuarios");
        DropForeignKey("dbo.Ratings", "Autor_UserId", "dbo.Usuarios");
        DropForeignKey("dbo.Eventos", "Usuario_UserId2", "dbo.Usuarios");
        DropForeignKey("dbo.Eventos", "Usuario_UserId1", "dbo.Usuarios");
        DropForeignKey("dbo.Eventos", "Usuario_UserId", "dbo.Usuarios");
        DropForeignKey("dbo.Eventos", "Sitio_Id", "dbo.Ubicacions");
        DropForeignKey("dbo.Eventos", "Rating_ID", "dbo.Ratings");
        DropForeignKey("dbo.Eventos", "Organizador_UserId", "dbo.Usuarios");
        DropForeignKey("dbo.Usuarios", "Evento_Id1", "dbo.Eventos");
        DropForeignKey("dbo.Usuarios", "Evento_Id", "dbo.Eventos");
        DropTable("dbo.Comentarios");
        DropTable("dbo.Ubicacions");
        DropTable("dbo.Ratings");
        DropTable("dbo.Eventos");
        DropTable("dbo.Usuarios");
    }
}

问题在于InitializeSimpleMembership类,因此删除了[InitializeSimpleMembership]注释和类,并将其添加到Global.asax.cs中:

 var migrator = new DbMigrator(new Configuration());
        migrator.Update();

        if (!WebSecurity.Initialized)
        {
            WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
        }

我不清楚是什么在创建这些表。我推断您创建了
Usuario
和创建的框架
Usuario
?您的会员资格提供商是否使用了WeventioDb数据库上下文?[Table(“Usuarios”)]的DataAnnotation应使用正确的名称创建表…@AnnL。我使用的是代码优先迁移,所以我想这会创建表(对于EF和ASP来说是非常新的),并随着初始迁移进行更新。@我会说是的,但是我怎么能检查它是否是真的?谢谢你们两位