zoukankan      html  css  js  c++  java
  • ASP.NET MVC5 之 AspNetUsers 表增加字段

    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 virtual UserSetting UsersSetting { get; set; }//增加两个表用来显示用户数据

        }

        public class ApplicationRole : IdentityRole
        {
            public ApplicationRole() : base() { }
            public ApplicationRole(string name) : base(name) { }
            public ApplicationRole(string name, string description)
                : this(name)
            {
                this.Description = description;
            }
    
            public string Description { get; set; }//角色表里新增加的字段
        }
        public class UserSetting
        {
            public string Id { get; set; }
            public string Theme { get; set; }
        }
    

      public class ApplicationDbContext : IdentityDbContext<ApplicationUser>    

      {        

               public ApplicationDbContext()            

              : base("APPDataConnection", throwIfV1Schema: false)       

                  {         }

            public static ApplicationDbContext Create()       

             {            

                    return new ApplicationDbContext();       

               }  

       }

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

    如何修改Id:

    https://github.com/TypecastException/AspNet-Identity-2-With-Integer-Keys/blob/master/IdentitySample/Models/IdentityModels.cs

    http://www.myexception.cn/vc-mfc/2000098.html

      

  • 相关阅读:
    jmeter接口自动化难点系列-jmeter多个线程组接口请求顺序问题
    Oracle 绝对和相对文件编号研究
    Oracle-索引分裂研究
    局域网内git项目克隆
    在CentOS中修改mariadb数据库存储位置
    Mariadb 通过binlog恢复删除(drop table)的数据
    高效边缘流处理方案:使用 OpenYurt 部署和管理 eKuiper
    负载均衡
    电信运营商基于 MQTT 协议 构建千万级 IoT 设备管理平台
    使用 MQTT.fx 接入 EMQ X Cloud
  • 原文地址:https://www.cnblogs.com/hanxingli/p/5340976.html
Copyright © 2011-2022 走看看