Use fields defined in EDM class improper of the database

0

I'm doing a procedure with which I want to transfer series to a place and show where they moved

to perform the action of showing the data, I use a datagrid and the following query

private void CargarGrilla()
        {
            decimal idDTraslado = Convert.ToDecimal(Request.QueryString["id"]);

            System.Text.StringBuilder sql = new System.Text.StringBuilder();
            sql.Append("SELECT tdt.id_traslado_DetalleSerie,tdt.id_traslado,tdt.id_trasladodetalle,tdt.serie_trasladada, bd.nombre as bodega_Actual, bt.nombre as bodega_proveniente, ");
            sql.Append("tdt.fecha_traslado_serie,tdt.id_usuario from Traslado_DetalleSerie tdt ");
            sql.Append("INNER JOIN traslado t on t.id_traslado = tdt.id_traslado ");
            sql.Append("INNER JOIN bodega bd on bd.id_bodega = t.id_bodega_destino ");
            sql.Append("INNER JOIN bodega bt on bt.id_bodega = t.id_bodega_origen ");
            sql.Append("WHERE tdt.id_trasladodetalle = @p0 ");

            var registros = db.Database.SqlQuery<Traslado_DetalleSerie>(sql.ToString(),idDTraslado).ToList();

            GridViewDatos.DataSource = registros;
            GridViewDatos.DataBind();
        }

The above works perfectly I get the result that I require

now my inconvenience comes

I have some fields referenced in the query to which I define an Alias because they are similar, although the value returned is different:

Denominated: bodega_Actual, bodega_proveniente (these fields are not specific to the table in the database)

In order to achieve that these could be visualized in the datagrid I had to create them in the model

here my model

public class Traslado_DetalleSerie
    {
        [Key][DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public decimal id_traslado_DetalleSerie { get; set; }
        public decimal id_traslado { get; set; }
        public decimal id_trasladodetalle { get; set; }
        public string serie_trasladada { get; set; }
        public Nullable<DateTime> fecha_traslado_serie { get; set; }
        public decimal id_usuario { get; set; }

        public string bodega_Actual { get; set; }
        public string bodega_proveniente { get; set; }

    }

My problem arises when I try to make the process of moving a new series to another warehouse, on reaching the line db.SaveChanges(); generates the following error

{"El nombre de columna 'bodega_Actual' no es válido.\r\nEl nombre de columna 'bodega_proveniente' no es válido."}

how do I declare them, so this does not happen

    
asked by Andrex_11 30.11.2018 в 16:17
source

0 answers