EntityType'DbGeography'没有定义键 [英] EntityType 'DbGeography' has no key defined

查看:147
本文介绍了EntityType'DbGeography'没有定义键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用 Visual Studio 2013 .NET 4.5.1 实体框架6 (最终版本,不是RC或测试版)。



要将DbGeography属性添加到我的实体,我在执行时收到此错误:

 在模型生成期间检测到一个或多个验证错误:
Geocoder.DbGeography::EntityType'DbGeography'没有定义键。
定义此EntityType的密钥。
DbGeographies:EntityType:EntitySet'DbGeographies'基于没有键定义的类型DbGeography。

我已经确认我没有参考旧版本的Entity Framework(讨论 here )。我一直在使用这篇文章和<一个href =http://msdn.microsoft.com/en-us/data/hh859721.aspx =nofollow noreferrer>这个MSDN文章的例子/信息,因为这是我第一次进入空间类型在.NET(和SQL Server,为此)。



这是我的实体:

  public class Location 
{
public int Id {get;组; }
public string Name {get;组; }
public string Address1 {get;组; }
public string Address2 {get;组; }
public string City {get;组; }
public virtual State State {get;私人集合}
public string ZipCode {get;组; }
public string ZipCodePlus4 {get;组; }
public DbGeography Geocode {get;组; }
public Hours Hours {get;组; }
public virtual ICollection< Language>语言{get;私人集合}
public virtual OfficeType OfficeType {get;私人集合

[JsonIgnore]
public virtual ICollection< ProviderLocation>供应商{get;私人集合
}

我做错了什么?

解决方案

事实证明,这与我在Codeplex here ,甚至他们的文档这里。我解释错了吗这两个链接都表明,在EF 6中,DbGeography数据类型从System.Data.Entity.Spatial移动到System.Data.Spatial,但相反的情况似乎是正确的。



我更改了

 使用System.Data.Spatial; 

 使用System.Data.Entity.Spatial; 

,它的工作原理。


Long time listener, first time caller (finally made an account here!)...

I am using Visual Studio 2013 with .NET 4.5.1 and Entity Framework 6 (final releases, not RC or beta).

When trying to add a DbGeography property to my entity, I get this error upon execution:

    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.

I have already confirmed I have no references to older versions of Entity Framework (discussed here). I have been using this post and this MSDN article for examples/information as this is my first foray into spatial types in .NET (and SQL Server, for that matter).

Here is my entity:

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; }
}

What am I doing wrong?

解决方案

This turned out to be the opposite of what I read from Microsoft's own response about a similar issue at Codeplex here, and even their documentation here. Did I interpret it wrong? Both of those links indicate that in EF 6, the DbGeography datatype was moved from System.Data.Entity.Spatial to just System.Data.Spatial, but the reverse seems true.

I changed

using System.Data.Spatial;

to

using System.Data.Entity.Spatial;

and it works.

这篇关于EntityType'DbGeography'没有定义键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆