Я пытаюсь запустить модель перевода, имея
public class Item
{
public Item
{
TextTranslationID = Guid.NewGuid();
DescriptionTranslationID = Guid.NewGuid();
TextTranslations = new HashSet<Translation>();
DescriptionTranslations = new HashSet<Translation>();
}
[Key]
public int ItemID { get; set; }
public Guid TextTranslationID { get; set; }
public Guid DescriptionTranslationID { get; set; }
[ForeignKey(nameof(TextTranslationID))]
public virtual ICollection<Translation> TextTranslations { get; set; }
[ForeignKey(nameof(DescriptionTranslationID))]
public virtual ICollection<Translation> DescriptionTranslations { get; set; }
}
и объект перевода
public class Translation
{
public Translation()
{
UniqueTranslationID = Guid.NewGuid();
}
[Key]
public Guid UniqueTranslationID { get; set; }
/// <summary>
/// The translation id, keyed with the language.
/// </summary>
[Required]
public Guid TranslationID { get; set; }
/// <summary>
/// The 2-char language code. eg "en", "es"
/// </summary>
[Required]
[StringLength(2, MinimumLength = 2)]
public string Language { get; set; }
[Required]
[StringLength(2000)]
public string Text { get; set; }
}
Это односторонняя связь, поэтому мне не нужен и не нужен объект Translation.Parent или что-то подобное в объекте Translation.
Сущность Item
является лишь одним из многих потребителей перевода, поэтому обратное свойство здесь не требуется.
Как видите, Item имеет две связи с переводами.
Я уже перепробовал так много комбинаций с построителем моделей для выполнения такой простой задачи в sql, но сгенерированный скрипт sql всегда хочет добавить DescriptionTranslationID и TextTranslationID в таблицу перевода.
...
migrationBuilder.CreateTable(
name: "Translations",
columns: table => new
{
UniqueTranslationID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
TranslationID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Language = table.Column<string>(type: "nvarchar(2)", maxLength: 2, nullable: false),
Text = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false),
DescriptionTranslationID = table.Column<int>(type: "int", nullable: true),
TextTranslationID = table.Column<int>(type: "int", nullable: true)
},
...
Как настроить два отношения "один ко многим" между элементом и переводом? Большое спасибо!