asp.net 身份 2.0 的范围用户 table
Extent user table of asp.net identity 2.0
我有一个 Web api 2 应用程序,我在其中使用了 asp.net identity 2.0 和 Entity framework。在我的 MySql 数据库中,我添加了这个 table 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`)
)
我需要在第二个 table 中合并这些 table 并在应用程序中识别 aspnetusers
的其他属性。
- 可以吗?
- 实现这个目标的步骤是什么?
如果要合并ajt_collaborator到AspNetUsers.
您可以将其他属性添加到 ApplicationUser 实体 class 来自 ajt_collaborator table 的镜像字段。
public class ApplicationUser : IdentityUser
{
//...
public string Address { get; set; }
}
您会发现 AspNetUser table 列在通用 IdentityUser 中定义为属性。
这将在重新创建架构时向 AspNetUsers 添加新字段 table。
或者您可以使用迁移而无需重新创建模式。 https://msdn.microsoft.com/en-us/data/jj591621.aspx
如果要将 AspNetUsers 合并到 ajt_collaborator。
然后您可以将 ApplicationUser 映射到 ajt_collaborator table.
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
//...
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>().ToTable("ajt_collaborator");
}
}
再次向 ApplicationUser 实体 class 添加所需的属性以镜像 ajt_collaborator table 中的列。
我有一个 Web api 2 应用程序,我在其中使用了 asp.net identity 2.0 和 Entity framework。在我的 MySql 数据库中,我添加了这个 table 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`)
)
我需要在第二个 table 中合并这些 table 并在应用程序中识别 aspnetusers
的其他属性。
- 可以吗?
- 实现这个目标的步骤是什么?
如果要合并ajt_collaborator到AspNetUsers.
您可以将其他属性添加到 ApplicationUser 实体 class 来自 ajt_collaborator table 的镜像字段。
public class ApplicationUser : IdentityUser
{
//...
public string Address { get; set; }
}
您会发现 AspNetUser table 列在通用 IdentityUser 中定义为属性。
这将在重新创建架构时向 AspNetUsers 添加新字段 table。 或者您可以使用迁移而无需重新创建模式。 https://msdn.microsoft.com/en-us/data/jj591621.aspx
如果要将 AspNetUsers 合并到 ajt_collaborator。
然后您可以将 ApplicationUser 映射到 ajt_collaborator table.
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
//...
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>().ToTable("ajt_collaborator");
}
}
再次向 ApplicationUser 实体 class 添加所需的属性以镜像 ajt_collaborator table 中的列。