I have a system and in this system there are some tables that are associative. As soon as I write to the DB the main table, I need to ensure that the new PK generated is written to three other tables, but you have to ensure that it is generated. The system runs on the web and this needs to be avoided if someone else is using the same routine and fire another PK, right?
Here I generate 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)
{}
}
}