What is the best alternative for recording data using a 3G connection?

2

I have the following situation: a header table with the fields:

IDJOGO           
IDMODALIDADE
IDUSUARIO
VALOR_JOGADO
HORA_JOGO

And a detail table:

IDJOGO
NUMERO_JOGO

In this case, would it be feasible to write the header, retrieve the last recorded ID for the user, and save the Items or would it be better to do a procedure and leave this responsibility with the database? / p>     

asked by anonymous 10.12.2015 / 02:24

1 answer

2
  

In this case, would it be feasible to record the header, retrieve the last recorded ID for the user and save the Items or would it be better to make a procedure and leave this responsibility with the database?

If you are using Entity Framework, you do not have to do this. You can do this as follows:

var modalidade = db.Modalidades.FirstOrDefault();
var usuario = /* Recupere aqui seu usuário */
var cabecalho = new Cabecalho 
{
    Modalidade = modalidade,
    Usuario = usuario,
    ValorJogado = 10,
    HoraJogo = DateTime.Now,
    Detalhes = new List<Detalhe> 
    {
        new Detalhe { NumeroJogo = 3 }
    }
};
db.Cabecalhos.Add(cabecalho);
db.SaveChanges(); // Grava cabecalho e o detalhe automaticamente.

By ADO.NET, you may have to use transactional scope and command two insert operations and a selection between them (bring the header record and set the FK in detail).

    
19.08.2016 / 04:27