0

私はこれを午後中ずっと解決しようとしてきましたが、空になってしまいました。私たちのスキーマはあまり正しくないようですが、私にはそれを変更する権限がありません。

基本的に、これらの 3 つのテーブルを組み合わせる必要があります。

dbo.Charity
    Id  (PK, int, not null)
    Name (varchar(100), not null)

dbo.CharityCountry
    CharityId (PK, FK, int, not null)
    CountryId (PK, FK, int, not null)

dbo.Country
    Id  (PK, int, not null)
    Name (varchar(100), not null)

そして、それらを EF モデルに入れます。

しかし、記事の多くが Mapping クラスでこれを行う方法を省略しているように見えるため、私は完全に混乱しています:

public class CharityMap : EntityTypeConfiguration<Charity>
{
    public CharityMap()
    {
        this.HasKey(t => t.Id);

        this.ToTable("dbo.Charity");

        this.Property(t => t.Id).HasColumnName("Id");
        this.Property(t => t.Name).HasColumnName("Name");
        ...
    }
 }

私が知る必要があるのは、... に何を入れるかということです。プライマリ エンティティに外部キーがない複合エンティティ アソシエーションをマッピングする方法がわかりません。

慈善オブジェクトは次のようになります。

public class Charity
{
    public int? Id { get; set; }
    public string Name { get; set; }
    public Country Country { get; set; }
}

国オブジェクト:

public class Country
{      
    public int? Id { get; set; }
    public string Name { get; set; }
}
4

1 に答える 1

0

あなたがサファリブックのオンラインアカウント http://my.safaribooksonline.com/book/-/9781449317867を持っている場合、ジュリー・ラーマンのこの本はとても役に立ちます。

あなたの例のように、ナビゲーションプロパティなしで外部キーを実行することに関するジュリーの無料記事を次に示します。可能ですが、扱いが難しいです。

http://msdn.microsoft.com/en-us/magazine/ee532098.aspx?sdmr=JulieLerman&sdmi=authors コラム「不在の外部キーで間に合わせる」を参照してください

于 2012-12-27T04:23:36.550 に答える