I'm working with the Entity Framework and I'm having a problem:
When I try to insert some data in a table it tells me that it's violating integrity of reference but the other table is normally populated and has the value i'm trying to insert.
Pedido pedido = new Pedido(); pedido.Data = DateTime.Now;
db.AddToPedido(pedido); db.SaveChanges();
EntityKey chave = db.CreateEntityKey("Pedido", pedido); Itens_Pedido item = new Itens_Pedido();
item.Pedido_Id = Convert.ToInt32(chave.EntityKeyValues.First().Value);
item.Carta_Id = Convert.ToInt32(Request.QueryString["Id"].ToString());
item.Quantidade = 1;
item.Foil = "N";
db.AddToItens_Pedido(item); db.SaveChanges();