Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 首先是成员代码-在不扩展类的情况下将FK添加到IdentityRole_C#_Entity Framework_Ef Code First_Asp.net Membership_Asp.net Identity - Fatal编程技术网

C# 首先是成员代码-在不扩展类的情况下将FK添加到IdentityRole

C# 首先是成员代码-在不扩展类的情况下将FK添加到IdentityRole,c#,entity-framework,ef-code-first,asp.net-membership,asp.net-identity,C#,Entity Framework,Ef Code First,Asp.net Membership,Asp.net Identity,正如标题所说,我想在不扩展/派生类的情况下,将FK添加到成员身份的IdentityRole中: 我有: public class ApiController { [Key] public int ApiControllerId { get; set; } public ICollection<IdentityRole> Roles { get; set; } 公共类ApiController { [关键] 公共int ApiControllerId

正如标题所说,我想在不扩展/派生类的情况下,将FK添加到成员身份的IdentityRole中:

我有:

 public class ApiController
    {
    [Key]
    public int ApiControllerId { get; set; }
    public ICollection<IdentityRole> Roles { get; set; }
公共类ApiController
{
[关键]
公共int ApiControllerId{get;set;}
公共ICollection角色{get;set;}
我想补充一点

public ICollection<ApiController> Controllers { get; set; }
公共ICollection控制器{get;set;}
添加到成员身份的IdentityRole类,以便EF创建多个关系表(即APIControlleroles)

我已经完成了我的家庭作业,我知道怎么做(通常),除了我的项目中没有IdentityRole的类定义。你知道我如何在没有类定义的情况下添加这个外键,或者更好的是,我如何获得这个类的副本吗


谢谢!

基于
IdentityRole

public class ApplicationRole : IdentityRole
{
      ...
      public ICollection<ApiController> Controllers { get; set; }
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser, Role, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>
{
      public ApplicationDbContext(): base("DefaultConnection") {}
}

public class ApiController
{
        [Key]
        public int ApiControllerId { get; set; }
        public ICollection<ApplicationRole> Roles { get; set; }
公共类应用程序角色:IdentityRole
{
...
公共ICollection控制器{get;set;}
}
公共类ApplicationDbContext:IdentityDbContext
{
public ApplicationDbContext():基(“DefaultConnection”){}
}
公共类ApiController
{
[关键]
公共int ApiControllerId{get;set;}
公共ICollection角色{get;set;}

谢谢您的回复,但从IdentityRole派生将创建一个似乎多余的鉴别器列。我不想扩展,我想修改现有类。ThanksIt不会创建鉴别器列。IdentityRole将不包括在dbContext中,而是扩展类