I have a question, how to insert data into a mysql table, using linq, I have the tables below:
I'm using the method below to insert:
public void inserirCarteira(float cpf, string codigo, double valor, int quant, double vtotal)
{
try
{
validarInserir(cpf, codigo, valor, quant, vtotal);
// instancia o banco de dados
bancotccEntities1 bco = new bancotccEntities1();
bco.Database.Connection.Open();
// cria um objeto
carteira cart = new carteira();
// popula o objeto
cart.cpf = cpf;
cart.codigo = codigo;
cart.valoracao = valor;
cart.qtdacao = quant;
cart.vtotalacao = vtotal;
// adciona um objeto ao banco
bco.AddTocarteira(cart);
//salva o objeto no banco
bco.SaveChanges();
bco.Database.Connection.Close();
}
catch (Exception e1)
{
throw new Exception(e1.Message.ToString());
}
}
I know that I have to use my foreign key but I do not know what it would look like: cart.card_card ?
If this is how I am going to enter values since the idusuario is the primary key of the user table and is auto increment, then I do not know what the value of this field will be at the time of insertion. >
Can anyone give me an idea how to do it?