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; }

    }

 

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