【问题标题】:Extent user table of asp.net identity 2.0asp.net identity 2.0的范围用户表
【发布时间】:2015-10-14 18:51:14
【问题描述】:

我有一个 web api 2 应用程序,我在其中使用了 asp.net 身份 2.0 和实体框架。在我的 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. 实现这一目标的步骤是什么?

【问题讨论】:

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


    【解决方案1】:

    如果您想将 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 表中的列。

    【讨论】:

      猜你喜欢
      • 2014-05-15
      • 1970-01-01
      • 1970-01-01
      • 2014-12-14
      • 2014-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多