abp-vnext-pro 实战(三,给用户表增加头像,工号,类型字段)

初识ABP vNext(5):ABP扩展实体 - xhznl - 博客园 (cnblogs.com)

Customizing Application Modules Extending Entities | Documentation Center | ABP.IO

 Advanced table mapping - EF Core | Microsoft Learn

    public class AbpUserExt : FullAuditedAggregateRoot<Guid>
    {
        /// <summary>
        /// 头像
        /// </summary>
        public string Avatar { get; set; }

        /// <summary>
        /// 个人介绍
        /// </summary>
        public string Introduction { get; set; }

        /// <summary>
        /// 用户编号(例如工号)
        /// </summary>
        public string UserCode { get; set; }

        /// <summary>
        /// 用户类型,0=后台,1=前台,2=分销商。。。
        /// </summary>
        public int UserType { get; set; }

    }

 

在XXXDbContextModelCreatingExtensions 的方法里

 builder.Entity<AbpUserExt>(b =>
            {
                b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users");
                b.ConfigureByConvention();
                b.Property(b => b.Avatar).IsRequired(false).HasMaxLength(255).HasComment("用户头像").HasColumnName(nameof(AbpUserExt.Avatar));
                b.Property(b => b.Introduction).IsRequired(false).HasMaxLength(255).HasComment("用户简介").HasColumnName(nameof(AbpUserExt.Introduction));
                b.Property(b => b.UserCode).IsRequired(false).HasMaxLength(50).HasComment("用户编号").HasColumnName(nameof(AbpUserExt.UserCode));
                b.Property(b => b.UserType).IsRequired(true).HasDefaultValue(0).HasComment("用户类型").HasColumnName(nameof(AbpUserExt.UserType));
                b.HasOne<IdentityUser>().WithOne().HasForeignKey<AbpUserExt>(x => x.Id);
            });

  

运行DbMigrator 项目,会出错。

System.InvalidOperationException:“'AbpUserExt.DeletionTime' and 'IdentityUser.DeletionTime' are both mapped to column 'DeletionTime' in 'AbpUsers', but are configured to use differing provider types ('DateTime' and 'DateTime?').”

改成

  public class AbpUserExt 
    { 
        public Guid Id { get; set; }
        /// <summary>
        /// 头像
        /// </summary>
        public string Avatar { get; set; }

        /// <summary>
        /// 个人介绍
        /// </summary>
        public string Introduction { get; set; }

        /// <summary>
        /// 用户编号(例如工号)
        /// </summary>
        public string UserCode { get; set; }

        /// <summary>
        /// 用户类型,0=后台,1=前台,2=分销商。。。
        /// </summary>
        public int UserType { get; set; }

    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章