我有以下型号:
public class Step {
[Key]
public int Id { get; set; }
[Required]
public String Name { get; set; }
public Workflow Workflow { get; set; }
public List<StepOption> Options{ get; set; }
internal StepDto toDto() {
return new StepDto {
Id = this.Id,
Name = this.Name,
};
}
}
和
public class StepOption {
[Key]
public int Id { get; set; }
[Required]
public String Name { get; set; }
public List<Step> Steps { get; set; }
}
因此,您可以看到Steps
和StepOptions
之间存在多对多关系。
当我运行数据库播种器时,使用以下种子:
var workflow = new Workflow {Id = 1, Name = "Some Workflow" };
context.Workflows.AddOrUpdate(w => w.Name, workflow);
var accept = new StepOption { Id = 1 ,Name = "Accept" };
var reject = new StepOption {Id = 2, Name = "Reject" };
var advies = new StepOption {Id = 3, Name = "Advies" };
context.StepOptions.AddOrUpdate(x => x.Name, accept, reject, advies);
var step1 = new Step {Id = 1, Name = "Start", Workflow = workflow, Options = new List<StepOption> { accept } };
var step2 = new Step { Id = 2, Name = "Validatie Bouwheer", Workflow = workflow, Options = new List<StepOption> { accept, reject } };
var step3 = new Step { Id = 3, Name = "Controlling1", Workflow = workflow };
var step4 = new Step { Id = 4, Name = "Adviezen", Workflow = workflow };
var step5 = new Step {Id = 5, Name = "Ondersteuning", Workflow = workflow };
var step6 = new Step { Id = 6, Name = "Directie", Workflow = workflow };
var step7 = new Step { Id = 7, Name = "Controlling2", Workflow = workflow };
var step8 = new Step { Id = 8, Name = "Reject", Workflow = workflow };
var step9 = new Step { Id = 9, Name = "Finish", Workflow = workflow };
context.Steps.AddOrUpdate(s => s.Id,
step1, step2, step3, step4, step5, step6, step7, step8, step9
);
DB中现在有3列:
但是现在我想知道如何从StepOptions
对象访问Steps
,它始终为空,尽管在数据库中StepOptionsSteps
正确链接