public class Question
{
public virtual Guid Index { get; set; }
public virtual string Content { get; set; }
}
public class Paper
{
public virtual Guid Index { get; set; }
public virtual ICollection<Question> Questions { get; set; }
}
如果不在OnModelCreating里手动设置Map
那么生成的数据库是这样的2个表:
表Questions
Index
Content
Paper_Index
表Papers
Index
怎么样才能让EF自动生成第三个表?
entityframework 多对多
------解决方案--------------------------------------------------------
HasMany(...).WithMany(...).Map(m => m.ToTable(...))
------解决方案--------------------------------------------------------
public class Question
{
public virtual Guid Index { get; set; }
public virtual string Content { get; set; }
public virtual ICollection<Paper> Papers{ get; set; }
}
public class Paper
{
public virtual Guid Index { get; set; }
public virtual ICollection<Question> Questions { get; set; }
}