タイトルが十分かどうかはわかりませんが、私が直面している問題について説明しようと思います。ちなみに、私はCode-FirstとFluent APIを初めて使用します。これは、これらを使用する最初の本番プロジェクトです。
基本的に、私が作成しようとしているWebアプリは多言語対応であり、次のフィールドを含むテーブルを作成することにしました(私が達成しようとしていることを説明するコメントを追加しました)。
public class Content
{
[Key]
// Required Key.
public int Id { get; set; }
[Required]
// Language (another class that stores culture and other culture specific info).
public Language Language { get; set; }
[Required]
// Text for the current field.
[Column(TypeName = "ntext")]
public string Text { get; set; }
[Required]
// The field Id, this stores what field the text above relates to.
// So if I have a field "Welcome", and the website has 5 languages, I'll have 5 entries with the same GUID
// but with different text and different language.
public virtual Guid FieldId { get; set; }
}
私は多くの解決策を試してきましたが、私が望むものを作成することができませんでした。私の最新のものは:
[Key]
public int Id { get; set; }
[Required]
[Key]
public Guid TitleId { get; set; }
[Required]
[Column("TitleId")]
public virtual ICollection<Content> Title { get; set; }
[Required]
public decimal Value { get; set; }
[Required]
[Key]
public Guid DescriptionId { get; set; }
[Required]
public virtual ICollection<Content> Description { get; set; }
そしてこれは文脈の中で(それが理にかなっているかどうかわからない):
modelBuilder.Entity<Winning>()
.HasMany(x => x.Description)
.WithRequired()
.Map(x =>
{
x.MapKey("DescriptionId", "FieldId")
.MapKey("TitleId", "FieldId");
});
基本的に私が欲しいのは、上記のオブジェクトをロードすると、そのGUIDを介して、関連するテキストのリスト(カルチャでフィルタリングするため、1つだけが望ましい)を取得し、テーブルContentが他のオブジェクトによって使用されるため、外部コンテンツ内のキーは私の問題を解決しません。