私はこれを午後中ずっと解決しようとしてきましたが、空になってしまいました。私たちのスキーマはあまり正しくないようですが、私にはそれを変更する権限がありません。
基本的に、これらの 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; }
}