@mrFrip
Преодолеваю прокрастинацию

Как удалить базовые поля и добавить свои в AspNetCore.Identity?

Изначальная структура Identity выглядит так
Базовая структура

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();
    }
}


Но из этого мне не нужны многие поля (для моего решения, например Email, или телефонный номер).

В тоже время, для идентификации пользователя, мне надо добавить некоторые собственные поля простых типов (string, int) и поле для реализации отношения многим-ко-многим (List), как это сделано, например, для связи таблиц Users и Roles через таблицу UsersRoles.

Как я могу это сделать, не потеряв при этом функциональность и возможности Identity?
  • Вопрос задан
  • 165 просмотров
Пригласить эксперта
Ответы на вопрос 1
firedragon
@firedragon
Не джун-мидл-сеньор, а трус-балбес-бывалый.
Удалять не удаляйте, а вот первичные ключи сам бог велел переопределить, в int или guid
Посмотрите в эту сторону
https://www.reflections-ibs.com/blog/articles/how-...
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы