protected void btn_save_Click(object sender, EventArgs e) { if (this.IsPostBack) { using (AlmacenEntities modelo = new AlmacenEntities()) { string sku = txtsku.Value; string nombre = txtname.Value; int cantidad = Convert.ToInt16(txtcantidad.Value); decimal precioVenta = Convert.ToDecimal(txtprecio.Value); decimal precioCosto = Convert.ToDecimal(txtcosto.Value); int bodega = Convert.ToInt16(idBodega.Value.ToString()); modelo.prApp_Producto_Insert(sku, nombre, cantidad, precioCosto, precioVenta, bodega, 1); IEnumerable <Producto> cat = from q in modelo.Producto where q.sku == sku select q; List <Producto> lista = cat.ToList(); if (lista.Count() > 0) { cod = lista[0].codProducto; } DateTime fec = DateTime.Parse(txtdate.Value); DetalleRegistro det = new DetalleRegistro() { fecha = fec, codProducto = cod, tipo = 1, cantidad = Convert.ToInt16(txtcantidad.Value), idBodega = Convert.ToInt16(idBodega.Value.ToString()) }; modelo.DetalleRegistro.Add(det); modelo.SaveChanges(); } Response.Redirect("WebProductos.aspx"); } }