很长时间的听众,第一次打电话的人(终于在这里打了个电话!)
我使用的是Visual 2013和.NET 4.5.1和Entity Framework6(最终版本,而不是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.我已经确认我没有引用实体框架的旧版本(讨论过这里)。我一直在使用这个职位和这篇MSDN文章作为示例/信息,因为这是我第一次尝试使用.NET (以及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; }
}我做错了什么?
发布于 2013-10-23 20:57:34
事实证明,这与我从微软自己对Codeplex 这里,甚至他们的这里的文件的类似问题的回应中看到的截然相反。我看错了吗?这两个链接都表明,在EF 6中,DbGeography数据类型从System.Data.Entity.Spatial移动到了System.Data.Spatial,但恰恰相反。
我改变了
using System.Data.Spatial;至
using System.Data.Entity.Spatial;而且起作用了。
发布于 2021-02-15 11:11:10
对于使用EF6 (在2021年)可能面临此问题的其他任何人,请尝试使用System.Data.Spatial.DbGeographyWellKnownValue而不是System.Data.Spatial.DbGeography。
这解决了我的问题。(不熟悉复杂的细节,但是如何通过这个方法解决错误。)
https://stackoverflow.com/questions/19551142
复制相似问题