【发布时间】:2015-09-28 18:55:58
【问题描述】:
我有两个具有多对多关系的表:ActionPlan 和 Responsible。
当我插入一个新的ActionPlan 和新的Responsible 时,表ActionPlanResponsible 上的记录被正确创建,但是当我尝试用现有的Responsible 添加一个新的ActionPlan 时,表@987654328 中的记录@ 未创建。
我以这种方式在 Json 中传递 ActionPlan 和责任:
{
"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();
行动计划实体:
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; }
【问题讨论】:
-
这个问题我很不清楚。
-
抱歉,我更新了我的问题。
-
如果您包含更多方法主体和您所引用的对象的定义(即责任和行动计划),也许会有所帮助
标签: c# .net entity-framework