Mapping to avoid data dublicating.(Just help with ideas)
Hello, guys! I have a question. If I have a domain model Customer that is used in services, but at the same time I'm using ASP.NET Core Identity, where the user already has all the properties of my Customer, I end up duplicating data and storing it in the database. My Customer model has no unique properties. Can I somehow configure the logic to map or retrieve information from the AspNetUsers table and map it to Customer (I need the ID or email)?
9 Replies
do you mean that Customer model in your domain is exactly like asp net Customer?
keeping in mind i would still use a custom model for Customer in my domain, you can add a dbset that returns asp net identity's Customer model mappend from your object in db, BUT the issue is that if you update packages and the model changes you will be forced to solve eventual issues before you can compile your code
so i would probably keep an external mapping and use that when i need to interact with identity
My Customer model has two properties: Id and Email. The AspNetUser model has these properties plus additional ones. I want to use the Customer domain model, but creating a new Customer is meaningless when a new user registers he already has same fields (and values that is needed for Customer). Instead, I’ll retrieve the email (and possibly the ID) from the database and map it to Customer.
are you keeping user data in program db or in another service? because if it's in your db then why was Customer model created for?
I made domain models and business logic layers and after added asp identity
so you are using Identity Customer to have a standard for a frontend? to validate claims/roles? something else?
Im using asp identityuser from asp.net identity library, and my domain customer model has no unique properties i need email and id only and i want to try take this info from AspIdentityUser table
Because now customer table has few columns and in this colums data is repeated (in I
Aspuser i already have email which is needed for my customer)
ah ok i didn't understand you have two tables in which you keep users' data
you have a dbcontext right? you have a dbset for AspNetUser? https://learn.microsoft.com/en-us/aspnet/core/security/authentication/customize-identity-model?view=aspnetcore-9.0
Identity model customization in ASP.NET Core
This article describes how to customize the underlying Entity Framework Core data model for ASP.NET Core Identity.
so what constraints you to migrate users/roles to identity models?
rather than trying map identity models to your models