My question is similar to this one, but in this case I do have a collection property on the parent referring to the childeren:
public class Parent
{
public int Id { get; set; }
public virtual ICollection<Child> Children { get; set; }
}
public class Child
{
public int Id { get; set; }
public int ParentId { get; set; }
}
And just as with the cited question, I don't want/need a Parent
property on Child
.
So how should the following syntax be altered to define the relationship?
modelBuilder.Entity<Child>()
.HasRequired(c => c.Parent) <---- no such property "Parent"
.WithMany(p => p.Children)
.HasForeignKey(c => c.ParentId);