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

Asked

Viewed 85 times

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, it would be feasible to record the header, perform the recovery of the last recorded ID to the user and save the Items or it would be better to do a Procedure and leave this responsibility with the database?

  • @Ricardo, friend, client server does not have 3G, it is to make the recording through a mobile, sending the data by a Web API made in C#

  • Cellular = client, Web API (runs on server) = server. Nomenclature only. Nothing wrong with using Precedent

  • @Ricardo, so you think you better make the creation of the trial because there might be some problem of losing data or do you have another justification? just for the better understanding. I thank you!

  • I deleted everything, I said nonsense. You can create the Precedent, but you can also make your application server make the move with ID. What the phone has to do is send everything at once to the server. Now I said right :)

  • @Ricardo ok! I appreciate the help!

  • And about data loss, if the application server is doing no loss, just be in transaction.

  • @Ricardo, you meant that when sending all the data, the processing will be done in the Controller and this way will not have data loss.

  • That’s right. And you will only have one call to the server. Best case scenario for the phone, The API must have a URL to receive all of them.

  • @Ricardo, now you’ve given me a "cat jump" tip to api getting everything together, problem is knowing how many numbers will have in detail

  • @itasouza, just one question. your application will run on a mobile device ?

  • @Marconciliosouza , yes!

  • @itasouza, in this case the ideal is to have web services for communication between your device and the database, in the case of your tables the best is to create two Process one for each table for the following reason, imagine that you will record more than one detail for each header (1 => N) then the parameters would be the same for a new detail.

  • You are using Entity Framework or ADO.NET?

Show 8 more comments

1 answer

2

In this case, it would be feasible to record the header, perform the recovery of the last recorded ID for the user and write the Items or it would be better to do a precedent and leave this responsibility with the database?

If you are using Entity Framework, you do not need to do this. You can do it 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 insertion operations and a selection between them (bring the header record and set the FK in detail).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.