Hi @lighto22 ,
using Microsoft identity in my asp.net core project ...
From your description, it seems that when create the project, you selected the Individual Accounts Authentication type, and you will use the Asp.net core Identity to manage users and roles, right?
Generally, when using Asp.net core Identity, to add custom user data to Identity table, we need to inherit the Identity Class, for example extending the AspNetUsers table, the appicationUsers class should like this:
public class appicationUsers:IdentityUser
{
public int Age { get; set; }
}
Then,
public class ApplicationDbContext : IdentityDbContext
{
public DbSet<appicationUsers> AppicationUsers { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
and change the Identity configuration to use the appicationUsers model
builder.Services.AddDefaultIdentity<appicationUsers>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
After migration, we can see the data table as below: the new property is add to the AspNetUsers table, instead of create a appicationUsers table.
when i migrate the DbContext to the database (sql server) two tables have been created (appicationUsers, AspNetUsers) and the relations created between ApplicationUsers and the rest of my tables not between AspNetUsers and them, also when i run the application and started to create users, they were loaded in AspNetUsers table.. so my question is ... how can my tables access to AspNetUsers table if no relation between them??
From your description, it seems that there is something wrong with your code, try to check your code. If the appicationUsers table and the AspNetUsers table doesn't have relationship, if is hard to query the related data. So, I suggest you could refer the above sample to modify your code, and then you can access the AspNetUsers table via the Dbcontext's AppicationUsers property.
More detail information about Identity Model customization, see Identity model customization in ASP.NET Core.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion