简体   繁体   English

EF 6相同类型的两个对象之间的导航属性

[英]EF 6 Navigation property between two objects of the same type

I have a EF db model called Booking 我有一个名为Booking的EF数据库模型

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

I need to be able to link two different bookings together, how can create a navigation property that gives me a link between each booking? 我需要将两个不同的预订链接在一起,如何创建一个导航属性,使我在每个预订之间建立链接?

Eg, Booking A needs a navigation property to Booking B and vice versa, Booking B needs a navigation property to Booking A. 例如,预订A需要导航属性到预订B,反之亦然,预订B需要导航属性到预订A。

Thanks. 谢谢。

I guess you could do like another navigation property: 我想你可以像另一个导航属性一样:

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; }
}

I hope it helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EF 5-6.1.1中的NullReferenceException,具有两个相同类型的导航属性 - NullReferenceException in EF 5-6.1.1 with two navigation properties to the same type EF:导航属性不是类型上的声明属性 - EF: The navigation property is not a declared property on type EF Code First属性到同一个表 - EF Code First Navigation Property to same table EF:同时包含导航属性和排除子导航属性 - EF: Include navigation property and exclude sub navigation property in same time 具有相同类型导航属性集合的EF6代码第一实体-如何告诉EF是什么关系? - EF6 Code First Entity with navigation property collection of same type - how do I tell EF what the relationship is? 每种类型的EF表,子类型表具有导航属性 - EF Table Per Type with Navigation property on Sub Type Table 是否可以在没有唯一外键的两个对象之间设置导航属性? - Can I setup a navigation property between two objects without a unique foreign key? EF在相同类型的不同上下文之间切换 - EF Switch between different contexts of same type EF导航属性如何在不同类之间转移? - How is an EF navigation property transferred between different classes? EF子查询无导航属性 - EF Subquery No Navigation Property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM