【发布时间】:2015-05-22 00:14:50
【问题描述】:
使用 EntityFramework 6.1.3,我有以下内容
public class RacesContext:DbContext
{
public DbSet<Race> Races { get; set; }
public DbSet<Sailboat> Sailboats { get; set; }
public DbSet<VenueParticipation> VenueParticipations { get; set; }
}
public class Crew
{
public int CrewId { get; set; }
public string Name { get; set; }
}
public class Sailboat
{
[Key]
public int SailboatId { get; set; }
public string Name { get; set; }
public string Skipper { get; set; }
public virtual ICollection<Crew> BoatCrew { get; set; }
}
public class VenueParticipation
{
[Key]
public int Id { get; set; }
public virtual ICollection<Sailboat> Boats { get; set; }
public virtual ICollection<Race> Races { get; set; }
}
public class Race
{
[Key]
public int RaceId { get; set; }
public string Venue { get; set; }
public DateTime Occurs { get; set; }
}
EF 使用正确的 PK 和 FK 创建 Creates the Crews 表,正如我所期望的那样。但是以一种意想不到的方式创建了 Races Sailboats、VenueParticipations 表。帆船得到了预期的 PK,但意外的 FK VenueParticipation_Id 和 Races 一样。我期待 VenueParticipations 表能够将 FK 传递给其他允许多对多关系的表。我确定我在这里遗漏了一些东西。任何建议都会很棒。
【问题讨论】:
标签: entity-framework