Tiago Redaelli
Tiago Redaelli

Reputation: 620

Custom IdentityUser

I'm trying to change from using default IdentityUser into custom AppUser. I've essentially added to the ApplicationDBContext and attempted to migrate and update the database. But this gives me the following error:

A key cannot be configured on 'AppUser' because it is a derived type. The key must be configured on the root type 'IdentityUser'. If you did not intend for 'IdentityUser' to be included in the model, ensure that it is not included in a DbSet property on your context, referenced in a configuration call to ModelBuilder, or referenced from a navigation property on a type that is included in the model.

How can I configure it on the root IdentiyUser as it's hidden from me?

The reason for this change is that I wish to attach user-details to an IdentityUser. Would it be easier to simply create another table for such things and just having a foreign key to the userId? What would be the drawbacks from such a implementation?

Reference https://learn.microsoft.com/en-us/aspnet/core/security/authentication/add-user-data?view=aspnetcore-3.0&tabs=visual-studio

Upvotes: 0

Views: 517

Answers (1)

LadySynammon
LadySynammon

Reputation: 68

My approach would be the later. Is to keep the IdentityUser as is and create a new table to hold the user details. The reason I would do it this way is separation of concerns. Profile data is separate for identity data. It also logically separates the entities so that somebody looking at this code four years from now can understand the entities. The only drawbacks of this implementation is that there are a second table and a foreign key. This would have slightly increased space and the possibility of broken relationships.

Upvotes: 1

Related Questions