使用方法
AddLink
和
DeleteLink
.
//
// POST: /Duty/Edit/5
[HttpPost]
public ActionResult Edit(Duty Model, FormCollection collection)
{
ctx.AttachTo("Duties", Model);
ctx.UpdateObject(Model);
// handle checkboxes
foreach (Worker w in ctx.Workers.Expand("Duties"))
{
bool isChecked = collection[w.Id.ToString()].Contains("t");
bool wasChecked = w.Duties.Contains(Model);
if (isChecked && !wasChecked)
{
ctx.AddLink(Model, "Workers", w);
}
else if (wasChecked && !isChecked)
{
ctx.DeleteLink(Model, "Workers", w);
}
}
ctx.SaveChanges();
return RedirectToAction("Index");
}
看到了吗
创建和修改关系链接
Updating the Data Service (WCF Data Services)