I have a project it’s about real estate so I created tables user
and linked it with estates
, and I learnt about identity.
When I migrate it hides the user
table because the ASP.NET Core identity already has a users
table, so how can I link asp.net user to users or how to link asp.net user to identity user
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
namespace Try.DAL.Entity
{
[Table("Users")]
public class Users
{
[Key]
public int Id { get; set; }
[StringLength(50)]
public string Fname { get; set; }
[StringLength(50)]
public string Lname { get; set; }
public string Email { get; set; }
public string Password { get; set; }
[StringLength(20)]
public string Phone { get; set; }
public DateTime Signupdate { get; set; }
public int Usergroupid { get; set; }
[ForeignKey("Usergroupid")]
public UserGroup Usergroup { get; set; }
public virtual ICollection<Estate> Estate { get; set; }
}
}
using Microsoft.EntityFrameworkCore;
using Try.DAL.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Try.Models;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
//using Try.Models;
namespace Try.DAL.Database
{
public class DbContainer : IdentityDbContext
{
public DbContainer(DbContextOptions<DbContainer> opts) : base(opts) { }
public virtual DbSet<RefreshToken> RefreshTokens { get; set; }
public DbSet<Users> Users { get; set; }
public DbSet<Ads> Ads { get; set; }
public DbSet<Clients> Clients { get; set; }
public DbSet<Feedback> Feedback { get; set; }
public DbSet<Interests> Interests { get; set; }
public DbSet<Orders> Orders { get; set; }
public DbSet<Estate> Estate { get; set; }
public DbSet<users> users{ get; set; }
2
Answers
You have to add the fields you want to add to the identity users table in the
applicationDbContext.cs
file like this:Modify your Dbcontext class as below:
And I have simpfied the class as below:
public class User:IdentityUser
Result:
The migration class:
and the database:
And if you modify the dbcontext class as follow:
You could find the properties of user class has been added to the ASPNetUser Table.