【问题标题】:EF 6 Navigation property between two objects of the same typeEF 6 相同类型的两个对象之间的导航属性
【发布时间】:2015-09-10 03:15:06
【问题描述】:

我有一个名为 Booking 的 EF 数据库模型

public class Booking
{
    public int ID { get; set; }
    public string Name { get; set; }
    // some other properties...
}

我需要能够将两个不同的预订链接在一起,如何创建一个导航属性来为我提供每个预订之间的链接?

例如,预订 A 需要到预订 B 的导航属性,反之亦然,预订 B 需要到预订 A 的导航属性。

谢谢。

【问题讨论】:

标签: c# .net entity-framework ef-code-first


【解决方案1】:

我猜你可以像另一个导航属性一样:

public class Booking
{
    // Your current code and... 

    // If you want One to One:
    public virtual Booking RelatedBooking { get; set; }
    // but if it's One to Many:
    public virtual ICollection<Booking> RelaitedBookings { get; set; }
}

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-16
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多