-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