2015-09-10 24 views
0

我有一個名爲預訂EF 6導航同一類型

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

我需要能夠以兩種不同的預訂鏈接在一起EF DB模式的兩個對象之間的財產,如何創造一個導航屬性,讓我每個預訂之間的鏈接?

E.g,預訂A需要的導航屬性來預訂B和反之亦然,預訂B需要的導航屬性來預訂A.

感謝。

+0

它只是一對一的關係,還是你還需要兩個以上的關聯? – Martin

+0

只有一對一的關係 – Russ

+0

這將有助於http://stackoverflow.com/questions/18398417/entity-framework-code-first-tree-model你只需要一個引用屬性和外鍵 – Martin

回答

0

我想你可以不喜歡另一個導航屬性:

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

我希望它能幫助。