-1
目前我下面Programming Entity Framework: Code First,在這裏筆者創建了這些模型類:EF代碼第一次沒有創建外鍵時,它應該有
namespace Model
{
public class Destination
{
public int DestinationID { get; set; }
public string Name { get; set; }
public string Country { get; set; }
public string Description { get; set; }
public byte[] Photo { get; set; }
public List<Lodging> Lodgings { get; set; }
}
public class Lodging
{
public int LodgingID { get; set; }
public string Name { get; set; }
public string Owner { get; set; }
public bool IsResort { get; set; }
public Destination Destination { get; set; }
}
}
,並表明,自動生成的數據庫有一個外鍵在Lodgings
表內的調用Destination_DestinationID
。但問題是在我的情況下它創建爲一個正常的int不是一個外鍵。
我使用EF5,我猜這本書使用EF4.1,這是不同的原因嗎?
你如何檢查它是否是外鍵? – qujck 2013-03-01 20:18:09
+1 @qujck。你爲什麼認爲Destination_DestinationID不是FK? – 2013-03-01 20:19:49
從VS裏面的Server explorer。我打開表格列並獲取'Destination_DestinationID'列的屬性。它在數據類型中表示** int **。此外,它的圖標看起來像其餘的列,而不是一個關鍵。 – 2013-03-01 20:20:07