Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.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

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# ASP.NET MVC标识关系_C#_Entity Framework_Asp.net Mvc 4 - Fatal编程技术网

C# ASP.NET MVC标识关系

C# ASP.NET MVC标识关系,c#,entity-framework,asp.net-mvc-4,C#,Entity Framework,Asp.net Mvc 4,我是ASP.NETMVC4新手,正在开发一个应用程序。在我的应用程序中,我有一个属性id为name的districts表。我想将此district表与identityModel.cs文件中的applicationUser关联。我的主要目标是在我的用户和地区之间建立一对多的关系。 与中一样,多个用户映射到单个地区。我在我的applicationUser课堂上试过这个 public class ApplicationUser : IdentityUser { public int Appli

我是ASP.NETMVC4新手,正在开发一个应用程序。在我的应用程序中,我有一个属性id为name的districts表。我想将此district表与identityModel.cs文件中的applicationUser关联。我的主要目标是在我的用户和地区之间建立一对多的关系。 与中一样,多个用户映射到单个地区。我在我的applicationUser课堂上试过这个

public class ApplicationUser : IdentityUser
{
    public int ApplicationUserID { get; set; }

    [ForeignKey("District")]
    public int DistrictID { get; set; }
    public virtual District District { get; set; }
}
这也是我的桌子

public class District
{
    public int DistrictID { get; set; }

    [Required]
    [Display(Name="District Name")]
    public string Name { get; set; }

    public string Status { get; set; }

    //Retrieving the region value through the id
    [Display(Name = "Region")]
    public int RegionID { get; set; }
    public virtual Region Region { get; set; }

    public virtual List<AreaCouncil> AreaCouncils { get; set; }

    public virtual List<ApplicationUser> ApplicationUsers { get; set; }
}
公共类地区
{
public int DistrictID{get;set;}
[必需]
[显示(名称=“地区名称”)]
公共字符串名称{get;set;}
公共字符串状态{get;set;}
//通过id检索区域值
[显示(Name=“Region”)]
public int RegionID{get;set;}
公共虚拟区域{get;set;}
公共虚拟列表区域委员会{get;set;}
公共虚拟列表应用程序用户{get;set;}
}
当我尝试搭建脚手架时,我收到以下错误消息:

无法检索“Basis.Models.Region”的元数据。在模型生成过程中检测到一个或多个验证>错误。 Basis.Models.IdentityUserLogin::实体类型“IdentityUserLogin”未定义键>。定义此实体类型的键。 Basis.Models.IdentityUserRole::实体类型“IdentityUserRole”未定义键>。定义此实体类型的键。“


有谁能帮我完成这段关系吗?

在应用程序中,您只需要一个地区的房产。除非您确实想要运行时多态性,否则您不希望它是虚拟的

我会给这房子起个别的名字,而不是地区。例如

public District HomeDistrict {get;set}

在ApplicationUser中,您只需要一个District属性。除非您确实想要运行时多态性,否则您不希望它是虚拟的

我会给这房子起个别的名字,而不是地区。例如

public District HomeDistrict {get;set}

IdentityUser
已具有主键。除去

public int ApplicationUserID { get; set; }

从您的
应用程序用户

标识用户
已经有了PK。除去

public int ApplicationUserID { get; set; }
应用程序用户