小编ois*_*lek的帖子

使用codefirst或流畅的API与同一实体的多对多(连接表)关系?

我正在使用EF 4.3.1 CodeFirst进行开发.我有一个机场表,如下所示:

 public class Airport
    {
        [Key]
        public int ID { get; set; }
        public string Name{ get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

我需要的是一张路由表,其中包含来自同一机场表的2个FK,如:

 public class Route
    {
        public int DepartureAirportID { get; set; }
        public int DestinationAirportID { get; set; }
        public virtual Airport DestinationAirport { get; set; }
        public virtual Airport DepartureAirport { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

怎么能实现这一目标?

many-to-many ef-code-first

5
推荐指数
1
解决办法
897
查看次数

标签 统计

ef-code-first ×1

many-to-many ×1