-3
我有两个表具有多对多关系:ActionPlan
和Responsible
。实体框架多对多关系插入不起作用
当我插入一个新的ActionPlan
和新Responsible
,上表ActionPlanResponsible
记录被正确创建,但是当我尝试添加一个新的ActionPlan
与现有Responsible
,不创建表ActionPlanResponsible
记录。
我路过ActionPlan和负责任的一个JSON里面那样:
{
"What": "Whatttasdasdt",
"Why": "Whyasdyyyy",
"How": "Hoasdwwwww",
"StartDate": "28/09/2015",
"EndDate": "28/09/2015",
"CreateDate": "28/09/2015",
"UpdateDate": "28/09/2015",
"State": "1",
"Where" : "Whasdere",
"Goal": {
"Id": "10"
},
"Responsibles": [{
"Id": "15"
}]
这就是我正在做的EF请求的方式......
foreach (var r in actionPlan.Responsibles)
{
context.Responsible.Attach(r);
}
context.ActionPlan.Add(actionPlan);
context.SaveChanges();
transaction.Commit();
的ActionPlan实体:
public long Id { get; set; }
public string What { get; set; }
public string Why { get; set; }
public string How { get; set; }
public DateTime StartDate { get; set; }
public virtual ICollection<Responsible> Responsibles { get; set; }
public DateTime EndDate { get; set; }
public Goal Goal { get; set; }
public virtual ICollection<FileActionPlan> Files { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
public string Where { get; set; }
public virtual ICollection<Task> Tasks { get; set; }
责任主体:
public byte State { get; set; }
public DateTime CreateDate { get; set; }
public DateTime UpdateDate { get; set; }
//public virtual ICollection<ActionPlan> ActionPlans { get; set; }
public virtual ICollection<Task> Tasks { get; set; }
public long Id { get; set; }
public Guid PersonId { get; set; }
这个问题对我来说很不清楚。 –
对不起,我更新了我的问题。 – Malinosqui
如果您包含更多的方法主体和您引用的对象的定义(即Reponsibles和ActionPlan),也许这会有所帮助 – Vlad274