C# 如何从第一个表中获取ID以记录第二个表?
如何从第一个表中获取ID以记录第二个表? 忆及该id和生成的自动C# 如何从第一个表中获取ID以记录第二个表?,c#,asp.net-mvc-3,visual-studio,C#,Asp.net Mvc 3,Visual Studio,如何从第一个表中获取ID以记录第二个表? 忆及该id和生成的自动 [HttpPost] public ActionResult Create(Chamados chamados, InteracoesChamados interacoesChamados) { if (ModelState.IsValid) { db.Chamados.Add(chamados); //interacoesChama
[HttpPost]
public ActionResult Create(Chamados chamados, InteracoesChamados interacoesChamados)
{
if (ModelState.IsValid)
{
db.Chamados.Add(chamados);
//interacoesChamados.ChamadoId = chamados.ChamadoId;
db.InteracoesChamados.Add(interacoesChamados);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(chamados);
}
评论和我想做的事情。
我需要从第一个表中获取代码并保存第二条记录。
最好的方法是什么?通过查看代码,我假设IteracoesChamados是Chamados的孩子。如果是,则设置
iteracoesChamados.Chamados = chamados
ID将自动分配。希望这有帮助