代码首先使用Visual Studio 2013模板与Asp.Net身份不起作用?

时间:2014-07-30 20:39:28

标签: c# entity-framework asp.net-identity

我正在本教程中使用代码优先更新我的 AspNetUsers 表。

http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx

这是我的IdentityModelClass:

using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Data.Entity;

namespace MTGWeb.Models
{
    // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : IdentityUser
    {
        public String Pais;
        public String Email;
        public DateTime UltimoLogin;
        public DateTime FechaRegistro;
        public String Tipo;
        public Boolean Activado;

    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection")
        {
        }

    }
}

我已经做了这个步骤:

  
      
  • 启用 - 错误 - 确定
  •   
  • 添加迁移“BlaBla ..”
  •   
  • 更新的数据库的
  •   

此步骤正确执行(不会因错误而停止),但不会更改任何内容。我遵循所有教程步骤,使用我的自定义数据,并调试数据在视图模型中发送正常,但数据库是问题。

我看到表AspNetUsers并没有保存任何字段。有任何想法吗?我可以注册用户,但只保存默认数据(Id, Username, PasswordHash,SecurityStamp and Discriminator

1 个答案:

答案 0 :(得分:1)

实体框架将属性映射到列。现在他们是田地。将它们更改为像这样的自动属性......

public class ApplicationUser : IdentityUser
{
    public String Pais { get; set; }
    public String Email { get; set; }
    public DateTime UltimoLogin { get; set; }
    public DateTime FechaRegistro { get; set; }
    public String Tipo { get; set; }
    public Boolean Activado { get; set; }

}