0
I have a system and this system has some tables that are associative. As soon as I write the main table in the comic book, I need to make sure that that new generated PK is recorded in three other tables, but you have to make sure it’s the one generated. The system runs on the web and it needs to be avoided that someone else is using the same routine and fire another PK, entede?
Here Gero the PK that will be FK in the other tables
[HttpPost]
public void GravaResponsavel(string _responsavel, bool _ativo)
{
using(RupturaEntities db = new RupturaEntities())
{
Responsavel resp = new Responsavel();
try
{
resp.NM_Responsavel = _responsavel;
resp.Ativo = _ativo;
db.Responsavel.Add(resp);
db.SaveChanges();
}
catch(Exception ex)
{}
}
}
I don’t know much about Ntity, but try it like this;
db.SaveChanges();
, adds avar id = resp.id;
to get the last inserted ID– Leonardo