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)
它的工作原理.