Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
Identidad en el usuario de C# ASP.NET Core Web API

Tengo un proyecto sobre bienes raíces, así que creé tablas user y las vinculé con estates , y aprendí sobre identidad.

Cuando migro, oculta la tabla de user porque la identidad de ASP.NET Core ya tiene una tabla de users , entonces, ¿cómo puedo vincular el usuario de asp.net a los usuarios o cómo vincular el usuario de asp.net con el usuario de identidad?

 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; }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Debe agregar los campos que desea agregar a la tabla de usuarios de identidad en el archivo applicationDbContext.cs de esta manera:

 namespace Try.DAL.Database { // You add this class here with custom fields. public class ApplicationUser : IdentityUser { // add properties here. [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; } } public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } 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; } } }
over 4 years ago · Santiago Trujillo Report

0

Modifique su clase Dbcontext como se muestra a continuación:

 public class UserTestDbContext : IdentityDbContext { public UserTestDbContext(DbContextOptions<UserTestDbContext> options) : base(options) { } public DbSet<_3._7.Models.User> User { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<User>().ToTable("User"); } }

Y he simplificado la clase de la siguiente manera:

Usuario de clase pública: IdentityUser

 { public int Id { get; set; } public string Name { get; set; } public string Password { get; set; } }

Resultado: La clase de migración: migración y la base de datos:

DB1 DB2

Y si modifica la clase dbcontext de la siguiente manera:

 public class UserTestDbContext : IdentityDbContext<User> { public UserTestDbContext(DbContextOptions<UserTestDbContext> options) : base(options) { } public DbSet<_3._7.Models.User> User { get; set; } }

Podría encontrar que las propiedades de la clase de usuario se han agregado a la tabla ASPNetUser. ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!