首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EntityType 'DbGeography‘没有定义密钥

EntityType 'DbGeography‘没有定义密钥
EN

Stack Overflow用户
提问于 2013-10-23 19:57:58
回答 2查看 6K关注 0票数 25

很长时间的听众,第一次打电话的人(终于在这里打了个电话!)

我使用的是Visual 2013.NET 4.5.1Entity Framework6(最终版本,而不是RC或beta)。

当试图向实体添加DbGeography属性时,执行时会得到以下错误:

代码语言:javascript
复制
    One or more validation errors were detected during model generation:
    Geocoder.DbGeography: : EntityType 'DbGeography' has no key defined.
    Define the key for this EntityType.
    DbGeographies: EntityType: EntitySet 'DbGeographies' is based on type 'DbGeography' that has no keys defined.

我已经确认我没有引用实体框架的旧版本(讨论过这里)。我一直在使用这个职位这篇MSDN文章作为示例/信息,因为这是我第一次尝试使用.NET (以及Server )中的空间类型。

这是我的实体:

代码语言:javascript
复制
public class Location
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Address1 { get; set; }
    public string Address2 { get; set; }
    public string City { get; set; }
    public virtual State State { get; private set; }
    public string ZipCode { get; set; }
    public string ZipCodePlus4 { get; set; }
    public DbGeography Geocode { get; set; }
    public Hours Hours { get; set; }
    public virtual ICollection<Language> Languages { get; private set; }
    public virtual OfficeType OfficeType { get; private set; }

    [JsonIgnore]
    public virtual ICollection<ProviderLocation> Providers { get; private set; }
}

我做错了什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-23 20:57:34

事实证明,这与我从微软自己对Codeplex 这里,甚至他们的这里的文件的类似问题的回应中看到的截然相反。我看错了吗?这两个链接都表明,在EF 6中,DbGeography数据类型从System.Data.Entity.Spatial移动到了System.Data.Spatial,但恰恰相反。

我改变了

代码语言:javascript
复制
using System.Data.Spatial;

代码语言:javascript
复制
using System.Data.Entity.Spatial;

而且起作用了。

票数 33
EN

Stack Overflow用户

发布于 2021-02-15 11:11:10

对于使用EF6 (在2021年)可能面临此问题的其他任何人,请尝试使用System.Data.Spatial.DbGeographyWellKnownValue而不是System.Data.Spatial.DbGeography

这解决了我的问题。(不熟悉复杂的细节,但是如何通过这个方法解决错误。)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19551142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档