EntityType'DbGeography'没有定义键

Jef*_*ume 25 .net c# entity-framework sqlgeography entity-framework-5

长时间听众,第一次来电(最后在这里开了帐户!)......

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

尝试向我的实体添加DbGeography属性时,执行时出现此错误:

    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.
Run Code Online (Sandbox Code Playgroud)

我已经确认我没有引用旧版本的Entity Framework(这里讨论).我一直在使用这篇文章这篇MSDN文章中的示例/信息,因为这是我第一次涉及.NET中的空间类型(以及SQL Server,就此而言).

这是我的实体:

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; }
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Jef*_*ume 32

事实证明,这是我从微软的约在Codeplex上一个类似的问题自己的反应看对面这里,甚至他们的文档在这里.我错误地解释了吗?这两个链接都表明在EF 6中,DbGeography数据类型已从System.Data.Entity.Spatial移动到System.Data.Spatial,但反过来似乎是正确的.

我变了

using System.Data.Spatial;
Run Code Online (Sandbox Code Playgroud)

using System.Data.Entity.Spatial;
Run Code Online (Sandbox Code Playgroud)

它的工作原理.

  • 是的,很好的观察RJB,这是一个问题.我喜欢保持我的域模型孤立,没有引用数据实现细节.我真的不得不在我的模型中添加对实体框架的引用,呃.我认为它可以通过一个聪明的数据配置图来修复,我会玩它并且如果我遇到任何可行的技术将会更新. (3认同)
  • 等等,这不好.这意味着核心层必须挂起对Entity Framework的依赖,而不仅仅是System.Data.Entity?如下所述:http://stackoverflow.com/a/34211927/1507899 (2认同)