Abp: Steps required to add custom property to AppUser

Created on 28 Oct 2019  路  12Comments  路  Source: abpframework/abp

So I have added an additional property to AppUser:

public virtual Guid? OriginId { get; set; }

I have add the migrations and synched the db schema successfully.

However I think I am missing a mappings step...
Question: Do I define a mapping expression somewhere to pick up my new property?
If so where should this be defined? In the imported identity module?

Most helpful comment

@274188A you are but it is not very easy at the moment. We are working on extensibility and will offer a solution for such cases.

All 12 comments

Yes - seen that but when I run the app I get a mapping exception - missing map for my new property

AutoMapper.AutoMapperConfigurationException:
Unmapped members were found. Review the types and members below.
Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type

For no matching constructor, add a no-arg ctor, add optional arguments, or map all of the constructor parameters

ProfileDto -> PersonalSettingsInfoModel (Destination member list)
Volo.Abp.Identity.ProfileDto -> Volo.Abp.Account.Web.Pages.Account.PersonalSettingsInfoModel (Destination member list)

Unmapped properties:
OriginId

at Volo.Abp.AutoMapper.AbpAutoMapperModule.<>c__DisplayClass2_1.g__ValidateAll|1(IConfigurationProvider config) in C:\Users\274188a\Source\Repos\abp\framework\src\Volo.Abp.AutoMapper\Volo\Abp\AutoMapper\AbpAutoMapperModule.cs:line 45
at Volo.Abp.AutoMapper.AbpAutoMapperModule.CreateMappings(IServiceProvider serviceProvider) in C:\Users\274188a\Source\Repos\abp\framework\src\Volo.Abp.AutoMapper\Volo\Abp\AutoMapper\AbpAutoMapperModule.cs:line 54
at Volo.Abp.AutoMapper.AbpAutoMapperModule.OnPreApplicationInitialization(ApplicationInitializationContext context) in C:\Users\274188a\Source\Repos\abp\framework\src\Volo.Abp.AutoMapper\Volo\Abp\AutoMapper\AbpAutoMapperModule.cs:line 24
at Volo.Abp.Modularity.OnPreApplicationInitializationModuleLifecycleContributor.Initialize(ApplicationInitializationContext context, IAbpModule module) in C:\Users\274188a\Source\Repos\abp\framework\src\Volo.Abp.Core\Volo\Abp\Modularity\DefaultModuleLifecycleContributor.cs:line 23
at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context) in C:\Users\274188a\Source\Repos\abp\framework\src\Volo.Abp.Core\Volo\Abp\Modularity\ModuleManager.cs:line 41
at Volo.Abp.AbpApplicationBase.InitializeModules() in C:\Users\274188a\Source\Repos\abp\framework\src\Volo.Abp.Core\Volo\Abp\AbpApplicationBase.cs:line 72
at Volo.Abp.AbpApplicationWithExternalServiceProvider.Initialize(IServiceProvider serviceProvider) in C:\Users\274188a\Source\Repos\abp\framework\src\Volo.Abp.Core\Volo\Abp\AbpApplicationWithExternalServiceProvider.cs:line 27
at Microsoft.AspNetCore.Builder.AbpApplicationBuilderExtensions.InitializeApplication(IApplicationBuilder app) in C:\Users\274188a\Source\Repos\abp\framework\src\Volo.Abp.AspNetCore\Microsoft\AspNetCore\Builder\AbpApplicationBuilderExtensions.cs:line 23
at Acme.BookStore.Web.Startup.Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) in C:\Users\274188a\source\repos\abp\samples\BookStore\src\Acme.BookStore.Web\Startup.cs:line 21
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.b__2(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Server.IISIntegration.IISSetupFilter.<>c__DisplayClass4_0.b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)

This is very strange, can you provide the steps to reproduce the problem?

add the following property to namespace Acme.BookStore.Users.AppUser

public virtual Guid? OriginId { get; set; }

In PersonalSettingsInfoModel add the following:

[StringLength(50)]
[Display(Name = "DisplayName:OriginId")]
public string OriginId { get; set; }

In BookStoreDbContextModelCreatingExtensions add:

public static void ConfigureCustomUserProperties<TUser>(this EntityTypeBuilder<TUser> b) where TUser: class, IUser { b.Property<Guid?>(nameof(AppUser.OriginId)).IsRequired(false); }

run code first migrations

In PersonalSettingsInfoModel add the following:

[StringLength(50)]
[Display(Name = "DisplayName:OriginId")]
public string OriginId { get; set; }

PersonalSettingsInfoModel is the class of the account module. How do you add new property?

I see - I should not have touched that. I added it by editing the module itself

I edited the Manage.cshtml file of that module simply because i wanted to see if i could customise the UI for the AppUser

This requires me to change the model so I can use the values on a page.

if i'm going down the wrong track happy to receive feedback...

You should not modify the source code of the module. You can override the components in the module in some cases.

So are we not allowed to add a new property to AppUser and have it editable in the UI?

@274188A you are but it is not very easy at the moment. We are working on extensibility and will offer a solution for such cases.

I understand - thanks for taking the time to look at my question

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mehdihadeli picture mehdihadeli  路  3Comments

vfabregat picture vfabregat  路  3Comments

hitaspdotnet picture hitaspdotnet  路  3Comments

derily picture derily  路  3Comments

hikalkan picture hikalkan  路  3Comments