我有一个 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
的其他属性在应用程序中得到识别。
- 可以这样做吗?
- 实现这一目标的步骤是什么?
最佳答案
如果您想将 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/