Open Closed

Issues while Extending AppUser Entity (One to Many) #452


User avatar
0
falsharif created

Hi team, First of all thanks alot of the amazing work with the ABP Commercial.

I am currently having an issue that seems obvious but i might be doing something wrong, would really appreciate your help as i am stuck.

So when i am trying to run my initial Db migration, i am getting this error :

System.InvalidOperationException: 'The property 'AppUser.ExtraProperties' could not be mapped, because it is of type 'Dictionary<string, object>' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.'

I followed the guide to extend AppUser Entity :

My AppUser Entity :

namespace Dukkantek.Users {

public class AppUser : FullAuditedAggregateRoot&lt;Guid&gt;, IUser
{
    #region Base properties

    /* These properties are shared with the IdentityUser entity of the Identity module.
     * Do not change these properties through this class. Instead, use Identity module
     * services (like IdentityUserManager) to change them.
     * So, this properties are designed as read only!
     */

    public virtual Guid? TenantId { get; private set; }

    public virtual string UserName { get; private set; }

    public virtual string Name { get; private set; }

    public virtual string Surname { get; private set; }

    public virtual string Email { get; private set; }

    public virtual bool EmailConfirmed { get; private set; }

    public virtual string PhoneNumber { get; private set; }

    public virtual bool PhoneNumberConfirmed { get; private set; }

    #endregion

    

    /* Add your own properties here. Example:
     *
     * public virtual string MyProperty { get; set; }
     * public string MyProperty { get; set; }
     *
     * If you add a property and using the EF Core, remember these;
     *
     * 1. update DukkantekDbContext.OnModelCreating
     * to configure the mapping for your new property
     * 2. Update DukkantekEfCoreEntityExtensionMappings to extend the IdentityUser entity
     * and add your new property to the migration.
     * 3. Use the Add-Migration to add a new database migration.
     * 4. Run the .DbMigrator project (or use the Update-Database command) to apply
     * schema change to the database.
     */


    
    public virtual ICollection&lt;Customer&gt; Customers { get; set; }
    private AppUser()
    {
        
    }
}

Now my AppUser has a one to many relationship with Customer -- > ** public virtual ICollection<Customer> Customers { get; set; } **

** and in my Customer Class:**

public class Customer : AuditedAggregateRoot&lt;Guid&gt;, ISoftDelete
{
 
    [Required]
    [StringLength(50)]
    public string Name { get; set; }

    [StringLength(15)]
    public string Phone { get; set; }

 public Guid UserId { get; set; }
 public virtual AppUser User { get; set; }






My DbContexts OnModelCreating  :  

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

        /* Configure the shared tables (with included modules) here */

        builder.Entity&lt;AppUser&gt;(b =>
        {
            b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users"); //Sharing the same table "AbpUsers" with the IdentityUser
            b.HasMany(p => p.Customers).WithOne().HasForeignKey(r => r.UserId);
         
            b.ConfigureExtraProperties();
            b.ConfigureByConvention();
            b.ConfigureAbpUser();
          
            /* Configure mappings for your additional properties.
             * Also see the DukkantekEfCoreEntityExtensionMappings class.
             */
        });
        
        

** DukkantekDbContextModelCreatingExtensions**

        builder.Entity&lt;Customer&gt;(b =>
        {
            b.ToTable(DukkantekConsts.DbTablePrefix + "Customers", DukkantekConsts.DbSchema);
            b.ConfigureByConvention(); //auto configure for the base class props

        });
        
        

** DukkantekEfCoreEntityExtensionMappings** public static void Configure() { DukkantekGlobalFeatureConfigurator.Configure(); DukkantekModuleExtensionConfigurator.Configure();

        OneTimeRunner.Run(() =>
        {
          
             * See the documentation for more:
             * https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
             */
       
            ObjectExtensionManager.Instance.MapEfCoreProperty&lt;IdentityUser, ICollection&lt;Customer&gt;>("Customers");
         
         
        });
    }

I feel like this line is probably the issue : ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, ICollection<Customer>>("Customers");

so how do i map IdentityUser to an ICollection of Customers ?? would really appreciate your support on this


1 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    May https://github.com/abpframework/abp-samples/tree/master/DocumentationSamples/CustomApplicationModules can help you.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09