Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.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/1/asp.net/30.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 4实体框架6中插入记录_C#_Asp.net_Asp.net Mvc_Entity Framework - Fatal编程技术网

C# 在连接表asp.net MVC 4实体框架6中插入记录

C# 在连接表asp.net MVC 4实体框架6中插入记录,c#,asp.net,asp.net-mvc,entity-framework,C#,Asp.net,Asp.net Mvc,Entity Framework,我正在asp.net MVC 4应用程序中使用Entity framework 6。我有两个表,其中包含多对多reationship配置文件和profilepositions。我创建了一个ID都为的连接表。我使用代码优先的方法。如何在此表中插入记录?我是否需要在两个表中为连接表或其他什么创建虚拟属性 public class Profile { public Guid ProfileId { get; set; } // other properties

我正在asp.net MVC 4应用程序中使用Entity framework 6。我有两个表,其中包含多对多reationship配置文件和profilepositions。我创建了一个ID都为的连接表。我使用代码优先的方法。如何在此表中插入记录?我是否需要在两个表中为连接表或其他什么创建虚拟属性

 public class Profile
    {
       public Guid ProfileId { get; set; }
       // other properties
    }

public class Account
    {
        public Guid AccountId { get; set; }
        // other properties

    }

// junction table
 public class AccountConnection
    {
       public int AccountID { get; set; }
       public int ProfileID { get; set; }
    }

请建议您按照以下方式构建表格:

public class Profile
{
   public Guid ProfileId { get; set; }
   public virtual ICollection<Account> Accounts { get; set; }

   // other properties
}

Public class Account
{
    public Guid AccountId { get; set; }
    public virtual ICollection<Profile> Profiles { get; set; }
    // other properties

}
公共类配置文件
{
公共Guid配置文件ID{get;set;}
公共虚拟ICollection帐户{get;set;}
//其他属性
}
公共类帐户
{
公共Guid帐户ID{get;set;}
公共虚拟ICollection配置文件{get;set;}
//其他属性
}
要将记录添加到任一表中,只需使用Profile.Accounts.add('Account Model')和Account.Profiles.add('Profile Model')


连接表是自动创建的

如果Junition表不止有两个主键怎么办?如果需要实际创建另一个表,该怎么办?