F
F
Frip2020-04-23 18:30:53
ASP.NET
Frip, 2020-04-23 18:30:53

How to remove base fields and add custom fields to AspNetCore.Identity?

The initial Identity structure looks like this

Basic Structure

using Microsoft.AspNetCore.Identity;
using System;

namespace Microsoft.AspNetCore.Identity
{
    //
    // Сводка:
    //     Represents a user in the identity system
    //
    // Параметры типа:
    //   TKey:
    //     The type used for the primary key for the user.
    public class IdentityUser<TKey> where TKey : IEquatable<TKey>
    {
        //
        // Сводка:
        //     Initializes a new instance of Microsoft.AspNetCore.Identity.IdentityUser`1.
        public IdentityUser();
        //
        // Сводка:
        //     Initializes a new instance of Microsoft.AspNetCore.Identity.IdentityUser`1.
        //
        // Параметры:
        //   userName:
        //     The user name.
        public IdentityUser(string userName);

        //
        // Сводка:
        //     Gets or sets the date and time, in UTC, when any user lockout ends.
        //
        // Примечания:
        //     A value in the past means the user is not locked out.
        public virtual DateTimeOffset? LockoutEnd { get; set; }
        //
        // Сводка:
        //     Gets or sets a flag indicating if two factor authentication is enabled for this
        //     user.
        [PersonalData]
        public virtual bool TwoFactorEnabled { get; set; }
        //
        // Сводка:
        //     Gets or sets a flag indicating if a user has confirmed their telephone address.
        [PersonalData]
        public virtual bool PhoneNumberConfirmed { get; set; }
        //
        // Сводка:
        //     Gets or sets a telephone number for the user.
        [ProtectedPersonalData]
        public virtual string PhoneNumber { get; set; }
        //
        // Сводка:
        //     A random value that must change whenever a user is persisted to the store
        public virtual string ConcurrencyStamp { get; set; }
        //
        // Сводка:
        //     A random value that must change whenever a users credentials change (password
        //     changed, login removed)
        public virtual string SecurityStamp { get; set; }
        //
        // Сводка:
        //     Gets or sets a salted and hashed representation of the password for this user.
        public virtual string PasswordHash { get; set; }
        //
        // Сводка:
        //     Gets or sets a flag indicating if a user has confirmed their email address.
        [PersonalData]
        public virtual bool EmailConfirmed { get; set; }
        //
        // Сводка:
        //     Gets or sets the normalized email address for this user.
        public virtual string NormalizedEmail { get; set; }
        //
        // Сводка:
        //     Gets or sets the email address for this user.
        [ProtectedPersonalData]
        public virtual string Email { get; set; }
        //
        // Сводка:
        //     Gets or sets the normalized user name for this user.
        public virtual string NormalizedUserName { get; set; }
        //
        // Сводка:
        //     Gets or sets the user name for this user.
        [ProtectedPersonalData]
        public virtual string UserName { get; set; }
        //
        // Сводка:
        //     Gets or sets the primary key for this user.
        [PersonalData]
        public virtual TKey Id { get; set; }
        //
        // Сводка:
        //     Gets or sets a flag indicating if the user could be locked out.
        public virtual bool LockoutEnabled { get; set; }
        //
        // Сводка:
        //     Gets or sets the number of failed login attempts for the current user.
        public virtual int AccessFailedCount { get; set; }

        //
        // Сводка:
        //     Returns the username for this user.
        public override string ToString();
    }
}


But I don't need many fields from this (for my solution like Email, or phone number).

At the same time, to identify the user, I need to add some custom fields of simple types (string, int) and a field to implement the many-to-many relationship (List), as is done, for example, to link the Users and Roles tables through the UsersRoles table .

How can I do this without losing the functionality and features of Identity?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-04-23
@firedragon

Do not delete, but God himself ordered to redefine primary keys, to int or guid
Look in this direction
https://www.reflections-ibs.com/blog/articles/how-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question