Open Closed

The property 'OrganizationUnit.ExtraProperties' could not be mapped because #1280


User avatar
0
yinlong created

I want to expand OrganizationUnit ,like appuser but,debug error the error message:

entity

using HF.EducationCloud.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.Identity;
using Volo.Abp.MultiTenancy;

namespace HF.EducationCloud.OrganizationUnits
{
    /// <summary>
    /// 组织扩展表
    /// </summary>
   public class AppOrganizationUnit : FullAuditedAggregateRoot<Guid>, IMultiTenant
    {
        public virtual Guid? TenantId { get; private set; }
        public virtual string DisplayName { get; set; }
        public virtual Guid? ParentId { get;  set; }
        /// <summary>
        /// 机构代码
        /// </summary>
        public string OrgCode { get; set; }
        public string OrgPic { get; set; }

        /// <summary>
        /// 机构属性:机构类别 0:小学 1:初中 2:高中 3:完中 4:机构 5:教学点 6:九年一贯制 7: 十二年一贯制
        /// </summary>
        public OrgCage OrgCage { get; set; }
        /// <summary>
        /// 省编码
        /// </summary>
        public string ProvinceCode { get; set; }

        /// <summary>
        /// 市编码
        /// </summary>
        public string CityCode { get; set; }

        /// <summary>
        /// 区编码
        /// </summary>
        public string AreaCode { get; set; }

        /// <summary>
        /// 机构类型:1:国家2:区域3:市4:区
        /// </summary>
        public OrgType OrgType { get; set; }
    }
}

EducationCloudDbContext

using Volo.Abp.EntityFrameworkCore.Modeling;
using Microsoft.EntityFrameworkCore;
using HF.EducationCloud.Teachers;
using HF.EducationCloud.Students;
using HF.EducationCloud.ClassManages;
using HF.EducationCloud.Users;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Identity;
using Volo.Abp.Users.EntityFrameworkCore;
using HF.EducationCloud.Schools;
using Volo.Abp.ObjectExtending;
using HF.EducationCloud.OrganizationUnits;
using Volo.Abp.Identity.EntityFrameworkCore;

namespace HF.EducationCloud.EntityFrameworkCore
{
    /* This is your actual DbContext used on runtime.
     * It includes only your entities.
     * It does not include entities of the used modules, because each module has already
     * its own DbContext class. If you want to share some database tables with the used modules,
     * just create a structure like done for AppUser.
     *
     * Don't use this DbContext for database migrations since it does not contain tables of the
     * used modules (as explained above). See EducationCloudMigrationsDbContext for migrations.
     */
    [ConnectionStringName("Default")]
    public class EducationCloudDbContext : AbpDbContext<EducationCloudDbContext>
    {
    
        public virtual DbSet<AppUser> Users { get; set; }

        public virtual DbSet<AppOrganizationUnit> AppOrganizationUnit { get; set; }

        /* Add DbSet properties for your Aggregate Roots / Entities here.
         * Also map them inside EducationCloudDbContextModelCreatingExtensions.ConfigureEducationCloud
         */

        public DbSet<Teacher> Teachers { get; set; }
        public DbSet<Student> Students { get; set; }
        public DbSet<ClassManage> ClassManages { get; set; }

        public virtual DbSet<ClassBindUser> ClassBindUser { get; set; }
        public virtual DbSet<ClassInfo> ClassInfo { get; set; }

     
        public EducationCloudDbContext(DbContextOptions<EducationCloudDbContext> options)
            : base(options)
        {

        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            /* Configure the shared tables (with included modules) here */
            
            builder.Entity<AppUser>(b =>
            {
                b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users"); //Sharing the same table "AbpUsers" with the IdentityUser

                b.ConfigureByConvention();
                b.ConfigureAbpUser();

                /* Configure mappings for your additional properties.
                 * Also see the EducationCloudEfCoreEntityExtensionMappings class.
                 */
            });


            builder.Entity<AppOrganizationUnit>(b =>
            {
                b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "OrganizationUnits");
               // b.ConfigureByConvention();
             
                //b.ConfigureExtraProperties();
                ////b.Ignore(x => x.ExtraProperties);
                //b.Property(x => x.OrgCode);
                //b.HasMany<OrganizationUnitRole>();
            });
            // add this..
            //builder.Entity<OrganizationUnit>(b =>
            //{
            //    b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "OrganizationUnits");

            //    b.ConfigureByConvention();

            //    b.Property(ou => ou.Code).IsRequired().HasMaxLength(OrganizationUnitConsts.MaxCodeLength)
            //        .HasColumnName(nameof(OrganizationUnit.Code));
            //    b.Property(ou => ou.DisplayName).IsRequired().HasMaxLength(OrganizationUnitConsts.MaxDisplayNameLength)
            //        .HasColumnName(nameof(OrganizationUnit.DisplayName));

            //    b.HasMany<OrganizationUnit>().WithOne().HasForeignKey(ou => ou.ParentId);
            //    b.HasMany(ou => ou.Roles).WithOne().HasForeignKey(our => our.OrganizationUnitId).IsRequired();

            //    b.HasIndex(ou => ou.Code);
            //});

            //builder.Ignore<OrganizationUnitRole>();
            
            /* Configure your own tables/entities inside the ConfigureEducationCloud method */

            builder.ConfigureEducationCloud();
        }
    }
}

EducationCloudEfCoreEntityExtensionMappings

using HF.EducationCloud.OrganizationUnits;
using HF.EducationCloud.Users;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;

namespace HF.EducationCloud.EntityFrameworkCore
{
    public static class EducationCloudEfCoreEntityExtensionMappings
    {
        private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

        public static void Configure()
        {
            EducationCloudGlobalFeatureConfigurator.Configure();
            EducationCloudModuleExtensionConfigurator.Configure();

            OneTimeRunner.Run(() =>
            {
                /* You can configure extra properties for the
                 * entities defined in the modules used by your application.
                 *
                 * This class can be used to map these extra properties to table fields in the database.
                 *
                 * USE THIS CLASS ONLY TO CONFIGURE EF CORE RELATED MAPPING.
                 * USE EducationCloudModuleExtensionConfigurator CLASS (in the Domain.Shared project)
                 * FOR A HIGH LEVEL API TO DEFINE EXTRA PROPERTIES TO ENTITIES OF THE USED MODULES
                 *
                 * Example: Map a property to a table field:

                     ObjectExtensionManager.Instance
                         .MapEfCoreProperty<IdentityUser, string>(
                             "MyProperty",
                             (entityBuilder, propertyBuilder) =>
                             {
                                 propertyBuilder.HasMaxLength(128);
                             }
                         );

                 * See the documentation for more:
                 * https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
                 */

                ObjectExtensionManager.Instance.MapEfCoreProperty<OrganizationUnit, string>(
                nameof(AppOrganizationUnit.OrgCode),
                (entityBuilder, propertyBuilder) =>
                {
                    propertyBuilder.HasMaxLength(255);
                });

                ObjectExtensionManager.Instance.MapEfCoreProperty<OrganizationUnit, string>(
              nameof(AppOrganizationUnit.OrgPic),
              (entityBuilder, propertyBuilder) =>
              {
                  propertyBuilder.HasMaxLength(255);
              });
                ObjectExtensionManager.Instance.MapEfCoreProperty<OrganizationUnit, int>(
                          nameof(AppOrganizationUnit.OrgCage),
                          (entityBuilder, propertyBuilder) =>
                          {
                              propertyBuilder.HasMaxLength(255);
                          });
                ObjectExtensionManager.Instance.MapEfCoreProperty<OrganizationUnit, string>(
                        nameof(AppOrganizationUnit.ProvinceCode),
                        (entityBuilder, propertyBuilder) =>
                        {
                            propertyBuilder.HasMaxLength(255);
                        });

                ObjectExtensionManager.Instance.MapEfCoreProperty<OrganizationUnit, string>(
                      nameof(AppOrganizationUnit.CityCode),
                      (entityBuilder, propertyBuilder) =>
                      {
                          propertyBuilder.HasMaxLength(255);
                      });
                ObjectExtensionManager.Instance.MapEfCoreProperty<OrganizationUnit, string>(
                    nameof(AppOrganizationUnit.AreaCode),
                    (entityBuilder, propertyBuilder) =>
                    {
                        propertyBuilder.HasMaxLength(255);
                    });
                ObjectExtensionManager.Instance.MapEfCoreProperty<OrganizationUnit, int>(
                        nameof(AppOrganizationUnit.OrgType),
                        (entityBuilder, propertyBuilder) =>
                        {
                            propertyBuilder.HasMaxLength(255);
                        });
                ObjectExtensionManager.Instance.MapEfCoreProperty<OrganizationUnit, string>(
                       nameof(AppOrganizationUnit.ExtraProperties),
                       (entityBuilder, propertyBuilder) =>
                       {
                           propertyBuilder.HasMaxLength(255);
                       });
                ObjectExtensionManager.Instance.MapEfCoreProperty<AppOrganizationUnit, string>(
                     nameof(OrganizationUnit.ExtraProperties),
                     (entityBuilder, propertyBuilder) =>
                     {
                         propertyBuilder.HasMaxLength(255);
                     });
            });
        }
    }
}


4 Answer(s)
  • User Avatar
    0
    jhsanc created

    I have this problem with ExtraProperties also but in AppUser

  • User Avatar
    0
    yinlong created

    anybody here?

  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer
    protected override void OnModelCreating(ModelBuilder builder)
        {
        base.OnModelCreating(builder);
        */ Configure the shared tables (with included modules) here */
        builder.Entity<AppUser>(b =>
        {
            b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users"); //Sharing the same table "AbpUsers" with the IdentityUser
    
            b.ConfigureByConvention();
            b.ConfigureAbpUser();
    
            /* Configure mappings for your additional properties.
             * Also see the EducationCloudEfCoreEntityExtensionMappings class.
             */
        });
    
    
        builder.Entity<AppOrganizationUnit>(b =>
        {
            b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "OrganizationUnits");
           // b.ConfigureByConvention();
    
            //b.ConfigureExtraProperties();
            ////b.Ignore(x => x.ExtraProperties);
            //b.Property(x => x.OrgCode);
            //b.HasMany<OrganizationUnitRole>();
        });
        // add this..
        //builder.Entity<OrganizationUnit>(b =>
        //{
        //    b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "OrganizationUnits");
    
        //    b.ConfigureByConvention();
    
        //    b.Property(ou => ou.Code).IsRequired().HasMaxLength(OrganizationUnitConsts.MaxCodeLength)
        //        .HasColumnName(nameof(OrganizationUnit.Code));
        //    b.Property(ou => ou.DisplayName).IsRequired().HasMaxLength(OrganizationUnitConsts.MaxDisplayNameLength)
        //        .HasColumnName(nameof(OrganizationUnit.DisplayName));
    
        //    b.HasMany<OrganizationUnit>().WithOne().HasForeignKey(ou => ou.ParentId);
        //    b.HasMany(ou => ou.Roles).WithOne().HasForeignKey(our => our.OrganizationUnitId).IsRequired();
    
        //    b.HasIndex(ou => ou.Code);
        //});
    
        //builder.Ignore<OrganizationUnitRole>();
    
        /* Configure your own tables/entities inside the ConfigureEducationCloud method */
    
        builder.ConfigureEducationCloud();
    }
    

    If you map extra properties to efcore, you need to configure them at OnModelCreating**.** Add .ConfigureByConvention() and .ConfigureExtraProperties().

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11