в настоящее время настраивает модель в проекте, над которым я работаю, и я врезался в стену и не могу понять, почему я получаю ошибку.
У меня есть два класса
public class CorePage : BaseClass
{
public CorePage()
{
this.PageContent = new HashSet<PageContent>();
this.PageAliases = new HashSet<PageAlias>();
this.isEditable = true;
}
public string DisplayLabel { get; set; }
public bool isEditable { get; set; }
public int? ParentPageId { get; set; }
public virtual CorePage ParentPage { get; set; }
public int TemplateId { get; set; }
public virtual Template Template { get; set; }
public int DefaultPageAliasId { get; set; }
public virtual PageAlias DefaultPageAlias { get; set; }
public virtual ICollection<PageAlias> PageAliases { get; set; }
public virtual ICollection<PageContent> PageContent { get; set; }
}
И
public class PageAlias : BaseClass
{
public PageAlias()
{
}
public string Alias { get; set; }
public int PageId { get; set; }
public virtual CorePage Page { get; set; }
}
Отношения между двумя классами настроены следующим образом.
public class CorePageConfiguration : EntityTypeConfiguration<CorePage>
{
public CorePageConfiguration()
{
HasOptional(cp => cp.ParentPage).WithMany().HasForeignKey(cp => cp.ParentPageId).WillCascadeOnDelete(false);
HasRequired(p => p.DefaultPageAlias).WithRequiredDependent().WillCascadeOnDelete(false);
}
}
И
public class PageAliasConfiguration : EntityTypeConfiguration<PageAlias>
{
public PageAliasConfiguration()
{
Property(pa => pa.Alias).IsRequired().HasMaxLength(500);
HasRequired(pa => pa.Page).WithMany(p => p.PageAliases).HasForeignKey(pa => pa.PageId).WillCascadeOnDelete(false);
}
}
Проблема в том, что я получаю эту ошибку:
Unable to determine the principal end of the 'Core.DataContext.PageAlias_Page' relationship. Multiple added entities may have the same primary key.
И я не могу определить, что пропустил.
Любая помощь будет высоко ценится.
Спасибо