Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EF代码首先没有';当外键应该有_C#_Asp.net_Entity Framework_Ef Code First_Foreign Keys - Fatal编程技术网

C# EF代码首先没有';当外键应该有

C# EF代码首先没有';当外键应该有,c#,asp.net,entity-framework,ef-code-first,foreign-keys,C#,Asp.net,Entity Framework,Ef Code First,Foreign Keys,目前,我在下面介绍作者创建这些模型类的地方: namespace Model { public class Destination { public int DestinationID { get; set; } public string Name { get; set; } public string Country { get; set; } public string Description { get; s

目前,我在下面介绍作者创建这些模型类的地方:

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; }
    }
}
名称空间模型
{
公务舱目的地
{
public int DestinationID{get;set;}
公共字符串名称{get;set;}
公共字符串国家{get;set;}
公共字符串说明{get;set;}
公共字节[]Photo{get;set;}
公共列表住宿{get;set;}
}
公务舱住宿
{
public int lodingId{get;set;}
公共字符串名称{get;set;}
公共字符串所有者{get;set;}
公共bool IsResort{get;set;}
公共目的地{get;set;}
}
}
并显示自动生成的数据库在
lodings
表中有一个名为
Destination\u DestinationID
外键。但问题是在我的例子中,它被创建为一个普通的int而不是一个外键


我使用的是EF5,我想这本书使用的是EF4.1,这就是造成这种差异的原因吗?

我复制了代码,我先使用EF代码5,生成的目的地ID确实是一个外键。问题不在于代码优先,而在于Visual Studio Server explorer,它没有显示这一点,我更喜欢使用SQL Server Management Studio执行与数据库相关的任务,它会显示列实际上是一个带有灰色键图标的外键。

如何检查它是否为外键?+1到@qujck。为什么您认为Destination_DestinationID不是FK?从VS中的服务器资源管理器中,我打开表列并获取
Destination_DestinationID
列的属性。它在数据类型中表示int。此外,它的图标看起来像其他列,而不是键。@RafaelAdel-您指的是主键,而不是外键。右键单击表并选择“打开表定义”。检查SQL的底部,您应该会看到约束。。。