Answer the question
In order to leave comments, you need to log in
How to set up one entity in EF with two external references to another entity?
I use code-first.
There is one essence
public class Stage
{
public int Id { get; set; }
public string Title { get; set; }
public string Body { get; set; }
public virtual ICollection<Motion> Motions { get; set; }
public Stage()
{
Motions = new List<Motion>();
}
}
public class Motion
{
public int Id { get; set; }
public string Description { get; set; }
public int NextStageId { get; set; }
public virtual Stage NextStage { get; set; }
public int OwnerStageId { get; set; }
public virtual Stage OwnerStage { get; set; }
}
public MotionMapper()
{
this.ToTable("Motion");
this.Property(x => x.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.Property(x => x.Id).IsRequired();
this.Property(x => x.Description).IsRequired();
this.HasRequired(x => x.OwnerStage)
.WithMany(x => x.Motions)
.HasForeignKey(x => x.OwnerStageId);
this.HasOptional(x => x.NextStage)
.WithMany(); // Вот тут я теряюсь что писать, перепробовал много вариантов)
}
Answer the question
In order to leave comments, you need to log in
stackoverflow.com/questions/9437366/entity-framewo...
I understand that you have a similar situation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question