基于ABP的AppUser对象扩展

 

在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
 
posted @   $我们都是好孩子$  阅读(147)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示