25

長年のリスナー、初めての発信者 (ついにここでアカウントを作成しました!)...

Visual Studio 2013.NET 4.5.1およびEntity Framework 6 (RC またはベータ版ではなく最終リリース)と共に使用しています。

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.

古いバージョンの Entity Framework への参照がないことを確認済みです (ここで説明します)。これは、.NET (さらに言えば SQL Server) の空間型への私の最初の進出であるため、例/情報としてこの投稿この MSDN の記事を使用してきました。

ここに私のエンティティがあります:

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

私は何を間違っていますか?

4

2 に答える 2

33

これは、Codeplex での同様の問題に関する Microsoft 自身の回答 (こちら) や、 Microsoft のドキュメント (こちら)から読んだものとは正反対であることが判明しました。私はそれを間違って解釈しましたか?これらのリンクは両方とも、EF 6 では DbGeography データ型が System.Data.Entity.Spatial から System.Data.Spatial に移動されたことを示していますが、その逆は真のようです。

私が変更され

using System.Data.Spatial;

using System.Data.Entity.Spatial;

そしてそれは動作します。

于 2013-10-23T20:57:34.603 に答える