首页 > Web开发 > 详细

ASP.NET MVC5 之 AspNetUsers 表增加字段

时间:2016-03-31 14:31:39      阅读:812      评论:0      收藏:0      [点我收藏+]

MVC5 执行数据库迁移时,会生成一些默认的数据表,但是在实际的工作中。若用到的时候,难免要增添一些字段。

1.AspNetUsers 增加字段

A.打开MVC中的 IdentityModels.cs 文件,具体代码如下:

    public class ApplicationUser : IdentityUser
    {
        #region 添加字段
        public string IsUser { get; set; }
        public string Tel { get; set; }
        public DateTime CreateTime { get; set; }
        public DateTime UpdateTime { get; set; }
        #endregion
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // 请注意,authenticationType 必须与 CookieAuthenticationOptions.AuthenticationType 中定义的相应项匹配
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // 在此处添加自定义用户声明
            return userIdentity;
        }
    }

  public class ApplicationDbContext : IdentityDbContext<ApplicationUser>    

  {        

           public ApplicationDbContext()            

          : base("APPDataConnection", throwIfV1Schema: false)       

              {         }

        public static ApplicationDbContext Create()       

         {            

                return new ApplicationDbContext();       

           }  

   }

B.执行MVC 数据迁移,具体可以参考前篇博客

  

 

ASP.NET MVC5 之 AspNetUsers 表增加字段

原文:http://www.cnblogs.com/hanxingli/p/5340976.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!