基于ABP的AppUser对象扩展

发布时间 2023-11-16 10:17:53作者: $我们都是好孩子$
 

在ABP中AppUser表的数据字段是有限的,现在有个场景是和老系统用户对接,需要在AppUser表中添加一个UId和IMId字段。本文以AppUser表扩展UId和IMId字段为例进行介绍。

一.在Abp默认解决方案Test.Identity.EntityFrameworkCore更改IdentityEfCoreEntityExtensionMappings类,该操作会向AbpUser实体添加UId和IMId属性

public static class IdentityEfCoreEntityExtensionMappings
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
ObjectExtensionManager.Instance
.MapEfCoreProperty<IdentityUser, string>(
"UId",
(entityBuilder, propertyBuilder) =>
{
propertyBuilder.HasMaxLength(128);
}
).MapEfCoreProperty<IdentityUser, string>(
"IMId",
(entityBuilder, propertyBuilder) =>
{
propertyBuilder.HasMaxLength(128);
}
);
});
}
}

二.数据库迁移和更新

1.设置DbMigrator为启动项,VS视图中打开"程序包管理控制台"

默认项目勾选 Test.Identity.EntityFrameworkCore

2.数据库迁移

输入命令add-migration add_appuser_UId

3.数据库更新

 update-database