C# 在连接表asp.net MVC 4实体框架6中插入记录
我正在asp.net MVC 4应用程序中使用Entity framework 6。我有两个表,其中包含多对多reationship配置文件和profilepositions。我创建了一个ID都为的连接表。我使用代码优先的方法。如何在此表中插入记录?我是否需要在两个表中为连接表或其他什么创建虚拟属性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
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表不止有两个主键怎么办?如果需要实际创建另一个表,该怎么办?