Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.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
Visual studio 2012 实体框架5空间误差_Visual Studio 2012_.net 4.5_Entity Framework 5 - Fatal编程技术网

Visual studio 2012 实体框架5空间误差

Visual studio 2012 实体框架5空间误差,visual-studio-2012,.net-4.5,entity-framework-5,Visual Studio 2012,.net 4.5,Entity Framework 5,我正在尝试使用EF5 beta 2、MVC和Visual Studio 2011/.NET 4.5使用空间类型保存位置信息。我使用的是“代码优先”方法,并一直遵循以下教程: 使用MVC开始使用EF- EF空间类型漫游- 这是我的模型: public class Location { public int LocationID { get; set; } public string Name { get; set; } public DbGeography CGLoc

我正在尝试使用EF5 beta 2、MVC和Visual Studio 2011/.NET 4.5使用空间类型保存位置信息。我使用的是“代码优先”方法,并一直遵循以下教程:

使用MVC开始使用EF-

EF空间类型漫游-

这是我的模型:

public class Location
{   
    public int LocationID { get; set; }
    public string Name { get; set; }
    public DbGeography CGLocation { get; set; }        
    public string LocationNotes { get; set; }
}
但是,当我尝试创建控制器时,会出现以下错误:

Unable to retrieve metadata for 'MVCSpatialTest.Models.Location'. One or more validation errors were detected during model generation:

System.Data.Edm.EdmEntityType::EntityType 'DbGeography' has no key defined. Define the key for this EntityType.

System.Data.Edm.EdmEntitySet: EntityType: EntitySet
DbGeographies is based on type DbGeography that has no keys defined.
如果我从模型中取出public dblocation{get;set;},一切都会正常工作,并创建数据库、控制器和视图

我的印象是LocationID自动被用作密钥,为什么会出现此错误


谢谢,

这是整个错误还是您刚刚发布了部分错误?这可能仅仅意味着MVC工具集还没有为EF5测试版的新特性做好准备。您使用的是什么版本的MVC?谢谢,我想您可能是对的,我刚刚更新了问题,包含了完整的错误消息。我用的是MVC4。不使用MVC,我会尝试一下。是的,当我不使用MVC时,空间类型可以很好地工作@Ladislav您能否将您的评论作为答案,以便我可以接受?您确定EntityFramework程序集的版本是5.0而不是4.4吗?您需要5.0才能使用空间要素。如果从4.x升级项目,它不会自动切换到5.0,则必须删除并重新添加程序集。