ABP Suite: How to Add the User Entity as a Navigation Property of Another Entity

Introduction

ABP Suite, a part of the ABP Commercial, is a productivity tool developed by the team behind the ABP Framework. The main functionality of the ABP Suite is to generate code for you.

In this post, I'll show you how to add the user entity as a navigation property in your new entity, by the help of the ABP Suite.

In the sample project MVC UI is used, but the same steps are applicable to the Angular UI as well.

Code Generation

Create a New Entity

Open the ABP Suite (see how). Create a new entity called Note, as an example entity.

create-note-entity

Then add a string property called Title, as an example property.

add-simple-property

Create AppUserDto

Note that, creating AppUserDto is not necessary after ABP v4.X

ABP Suite needs a DTO for the target entity (user, in this case) in order to define a navigation property.

To do this, create a new folder called "Users" in *.Application.Contracts then add a new class called AppUserDto inherited from IdentityUserDto.

create-appuserdto

We should define the object mapping to be able to convert the AppUser objects to AppUserDto objects. To do this, open YourProjectApplicationAutoMapperProfile.cs and add the below line:

CreateMap<AppUser, AppUserDto>().Ignore(x => x.ExtraProperties);

create-mapping

Creating such a DTO class may not be needed for another entity than the AppUser, since it will probably be already available, especially if you had created the other entity using the ABP Suite.

Define the Navigation Property

Get back to ABP Suite, open the Navigation Properties tab of the ABP Suite, click the Add Navigation Property button. Browse AppUser.cs in *.Domain\Users folder. Then choose the Name item as display property. Browse AppUserDto.cs in *.Contracts\Users folder. Choose Users from Collection Names dropdown.

add-user-navigation

Generate the Code!

That's it! Click Save and generate button to create your page. You'll see the following page if everything goes well.

final-page

This is the new page that has been created by the ABP Suite. It can perform the fundamental CRUD operations. Also, it has the "App user" column that shows the related user name (you can easily change the automatically created "App user" title from the Entity Name field of the navigation property creation screen).

Picking Users from Look Up Table

We used dropdown element to select a user from the user list. If you have a lot of users, then it's good to pick a user from a look up table. A look up table is a modal window that lets you filter data and pick one. To do this, get back to Suite and click Edit button of user navigation which is set as AppUserId name. Choose "Modal" from the "UI Pick Type" field. Then click Save and generate button to recreate your page.

ui-pick-type-modal

After successful code generation, you'll see the the user can be picked from user table.

ui-pick-type-modal2

About the ABP Commercial RC

This example has been implemented with ABP Commercial 3.1.0. If you have not installed the ABP CLI and ABP Suite, follow the next steps:

1- Uninstall the current version of the CLI and install:

dotnet tool install --global Volo.Abp.Cli --version 3.1.0

2- Uninstall the current version of the Suite and install:

dotnet tool uninstall --global Volo.Abp.Suite && dotnet tool install -g Volo.Abp.Suite --version 3.1.0 --add-source https://nuget.abp.io/<YOUR-API-KEY>/v3/index.json

Don't forget to replace the <YOUR-API-KEY> with your own key!

abp-suite
Kishore Sahasranaman 169 weeks ago

How to Add the User Entity as a Navigation Property of Another Entity in ABP Framework (Not Commercial)?

Alper Ebiçoğlu 169 weeks ago

User AppUser class in your Domain project.

Ferruh KARGAR 165 weeks ago

How to Add the User Entity as a Navigation Property of Another Entity (Customer) in commercial abp. there is no AppUser in Domain project (in module not application)

Alper Ebiçoğlu 165 weeks ago
beuko 151 weeks ago

I am trying to implement this in abp.cli 4.3.0 but it is not working, keep getting error "The property 'AppUser.ExtraProperties' could not be mapped".

Alper Ebiçoğlu 151 weeks ago

you probably skipped this step

CreateMap<AppUser, AppUserDto>().Ignore(x => x.ExtraProperties);

1
beuko 151 weeks ago

Hello Alper. No, I did not skip this step because this line is auto generated. Also AppUser and AppUserDto are auto generated in abp suite 4.3.0 version. How did you create your test project? With separated identity server?

jhsanc 151 weeks ago

I do this but I have this error: System.InvalidOperationException: The property 'AppUser.ExtraProperties' could not be mapped because it is of type 'ExtraPropertyDictionary', 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'. The same error of beuko and the solution of Alper not found. https://github.com/abpframework/abp/issues/1517

mikle.jk2009@gmail.com 56 weeks ago

Mostbet - bu eng yaxshi tikish sayti, chunki u bozorlar va tikish imkoniyatlarining katta tanloviga ega. Shuningdek, u yangi mijozlar uchun turli xil bonuslarni taqdim etadi https://mosbetuz.com/uz . Mostbet dunyoning eng yaxshi bukmeykerlaridan biri bo'lib, bozorlar va pul tikish imkoniyatlarining ajoyib assortimentiga ega. Ular yangi mijozlar uchun bonuslarni taklif qilishadi va tanlash uchun o'yinlarning katta tanloviga ega.

Mostbet Uz 35 weeks ago

Salom. Men sizni bukmekerlar haqida gapirayotganingizni ko'raman. Agar siz bukmekerlik shoxobchasining hamkori bo'lmoqchi bo'lsangiz, unda mosbet-uz-mostbet.com ushbu havolaga o'ting va bukmekerlik kompaniyasi hamkoriga aylaning. Sizga kerak bo'lgan narsa - referal havolasini tarqatish va odamlarni bukmekerga jalb qilish orqali pul ishlash. Agar sizning shaxsiy veb-saytingiz yoki blogingiz bo'lsa, havolani tarqatish sizga osonroq bo'ladi, shuning uchun pul ishlashning bu usuli bloggerlar va veb-saytga ega odamlarga mos keladi.