mysql - asp.net Identity 2.0的Extent用户表

标签 mysql .net entity-framework asp.net-mvc-4 asp.net-identity

我有一个 Web api 2 应用程序,其中使用了 ASP.NET Identity 2.0 和 Entity Framework 。在我的 MySql 数据库中,我添加了此表 ajt_collaborator

CREATE TABLE `ajt_collaborator` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `marital_status` enum('M','MLLE','MME') DEFAULT NULL,
  `address` text,
  `Nom` text,
  `Prenom` text,
  `id_user_fk` varchar(128) NOT NULL,
  `deletion_date` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `collaborator_user_fk` (`id_user_fk`),
  CONSTRAINT `collaborator_user_fk` FOREIGN KEY (`id_user_fk`) REFERENCES `aspnetusers` (`Id`)
)  

指的是aspnetusers

CREATE TABLE `aspnetusers` (
  `Id` varchar(128) NOT NULL,
  `Hometown` text,
  `Email` varchar(256) DEFAULT NULL,
  `EmailConfirmed` tinyint(4) NOT NULL,
  `PasswordHash` text,
  `SecurityStamp` text,
  `PhoneNumber` text,
  `PhoneNumberConfirmed` tinyint(4) NOT NULL,
  `TwoFactorEnabled` tinyint(4) NOT NULL,
  `LockoutEndDateUtc` datetime DEFAULT NULL,
  `LockoutEnabled` tinyint(4) NOT NULL,
  `AccessFailedCount` int(11) NOT NULL,
  `UserName` varchar(256) NOT NULL,
  PRIMARY KEY (`Id`)
) 

我需要将这些表合并到第二个表中,并使 aspnetusers 的其他属性在应用程序中得到识别。

  1. 可以这样做吗?
  2. 实现这一目标的步骤是什么?

最佳答案

如果您想将 ajt_collaborator 合并到 AspNetUsers。

您可以向 ajt_collaborator 表中的 ApplicationUser 实体类镜像字段添加其他属性。

public class ApplicationUser : IdentityUser
{
    //...

    public string Address { get; set; }
}

您会发现 AspNetUser 表列在通用 IdentityUser 中定义为属性。

当重新创建架构时,这将向 AspNetUsers 表添加新字段。 或者您可以使用迁移,而无需重新创建架构。 https://msdn.microsoft.com/en-us/data/jj591621.aspx

如果您想将 AspNetUsers 合并到 ajt_collaborator。

然后您可以将 ApplicationUser 映射到 ajt_collaborator 表。

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    //...

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<ApplicationUser>().ToTable("ajt_collaborator");
    }
}

再次向 ApplicationUser 实体类添加所需属性以镜像 ajt_collaborator 表中的列。

关于mysql - asp.net Identity 2.0的Extent用户表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33133347/

相关文章:

c# 控制台应用程序保持在任务计划程序 Windows 2016 中运行的状态

c# - 无法解析格式为 2013-09-17T05 :15:27. 947 的日期字符串

entity-framework - OData 包括通过部分类添加到 Entity Framework 模型的 "Custom Properties"

c# - 将两个不同类型的列表匹配在一起

MySQL存储过程设计题V2。回避或等级制度?

mysql - 无论年份如何,在mysql中选择两个日期之间的数据

mysql - 按列值选择前 N 条记录

c# - 与 Windows 命名管道 (.Net) 的异步双向通信

php - 从 <option> 中选择多个字段并将它们添加到数据库

c# - Linq 查询转换为 SQL 弄乱了空参数值