.net core 2.2 修改IdentityUser主键标识类型
.net core2.2,生成WebApi或者MVC项目后,Identity
1.增加ApplicationUser.cs文件,内容如下
public class ApplicationUser : IdentityUser<int>
{ } public class ApplicationRole : IdentityRole<int>
{ }
2.修改ApplicationDbContext.cs文件,内容如下
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, int>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
3.修改Startup.cs,内容如下
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
}); services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DriverBase")));
services.AddDefaultIdentity<ApplicationUser>()
.AddDefaultUI(UIFramework.Bootstrap4)
.AddEntityFrameworkStores<ApplicationDbContext>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
4.在PM运行Add-Migration CreateIdentitySchema
PM> Add-Migration CreateIdentitySchema
Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.2.1-servicing-10028 initialized 'ApplicationDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
To undo this action, use Remove-Migration.
5.在PM运行Update-Database
PM> Update-Database
6.打开Views\Shared\_LoginPartial.cshtml文件,找到如下内容
@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
修改为:
@using Microsoft.AspNetCore.Identity
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
.net core 2.2 修改IdentityUser主键标识类型的更多相关文章
- Oracle的分区操作和修改分区主键
1.增加一个分区ALTER TABLE sales ADD PARTITION jan96 VALUES LESS THAN ( '01-FEB-1999' ) TABLESPACE tsx;增加一个 ...
- 从Redis生成数据表主键标识
对于MySql的全局ID(主键),我们一般采用自增整数列.程序生成GUID.单独的表作为ID生成器,这几种方案各有优劣,最终效率都不能说十分理想(尤其海量数据下),其实通过Redis的INCR可以很方 ...
- cassandra表中主键的类型
cassandra表中主键的类型及区分? 一.类型及区分 二.参考文章 一.类型及区分 Cassandra的4种Key Primary Key 主键 Composite Key,Compound Ke ...
- mysql修改数据 -- 主键冲突
mysql 插入数据唯一键冲突 前提: 修改数据三种可用的方法解决主键冲突的问题 1. insert into ... on duplicate key update set ... 2. updat ...
- asp.net MVC Model 类的主键 int类型、string类型、GUID类型。
在使用asp.net mvc进行定义 模型类的时候,一般情况下,我们都会定义一个属性为 int iD{get;set;} 或为int ClassNameID {get;set;},在这种情况下 1.I ...
- mysql修改联合主键
参考 https://blog.csdn.net/BockSong/article/details/80933477 alter table TABNAME drop primary key; alt ...
- 怎么修改mysql主键(id)的值为自增
alter table tb_name modify id int auto_increment primary key
- sqlserver修改表主键自增
alter table tname add id int identity(1,1)
- 在iOS7中修改键盘Return键的类型
今天将之前运行在iOS7之前的一段代码拿出来,在iOS7的机器上运行,发现键盘上的ReturnKeyType不能被修改了. 经过几番查找资料,了解到iOS7中UISearchBar的结构发生了变化,将 ...
随机推荐
- .NET 使用 Azure Blob 存储图片或文件
使用的是VS2017 一.先使用 NuGet 获取这两个包. 执行以下步骤: 在“解决方案资源管理器”中,右键单击你的项目并选择“管理 NuGet 包”. 1.在线搜索“WindowsAzure.St ...
- [转]Linux编译和安装boost库
1. 下载boost安装包并解压缩 到http://www.boost.org/下载boost的安装包,以boost_1_58_0.tar.gz为例 下载完成后进行解压缩: tar zxvf boos ...
- Git 日常操作
本地新建Git库步骤: 初始化git库:git init 建立本地和远程的关联: git remote add origin ip:端口/ 项目.git 从远程下载所有分支到本地:git fetch ...
- VS重新生成项目失败,但是不报错
相信很多同行可能都遇到这种情况: 使用SVN或者其他项目管理工具checkout一个项目后,重新生成项目后,生成失败了,但是没有显示任何错误: 其实,这个大多数是因为类库里面的引用失效导致的,我们可以 ...
- python解决四舍五入问题
小数问题是计算机编程中大部分语言都会遇到的问题,尤其是在内容中涉及到评分.金额计算等等,本人一般在解决需求中固定小数位的数字计算时,都会先将其放大整10的倍数至整数,然后计算.存储,只有在显示的时候再 ...
- xxl-job源码分析
1 调度中心API服务 1.任务结果回调服务: 2.执行器注册服务: 3.执行器注册摘除服务: 4.触发任务单次执行服务,支持任务根据业务事件触发: API暴露代码:com.xxl.job.admin ...
- Docker安装使用battery historian
apt-get insatll docker.io battery historian ubuntu下使用 首先要确保是google浏览器,然后用命令行 google-chrome --proxy-s ...
- 知识点:Mysql 索引原理完全手册(2)
知识点:Mysql 索引原理完全手册(1) 知识点:Mysql 索引原理完全手册(2) 知识点:Mysql 索引优化实战(3) 知识点:Mysql 数据库索引优化实战(4) 八. 联合索引与覆盖索引 ...
- Logic and Proofs--离散数学
Propositions: A proposition is a declarative sentence(that is, a sentence that declares a fact ) tha ...
- Docker CMD in detail
CMD CMD 指令就是用于指定默认的容器主进程的启动命令的,我们直接 docker run -it ubuntu 的话,会直接进入 bash.我们也可以在运行时指定运行别的命令,如 docker r ...