locked
error with ef RRS feed

  • Question

  • please i need some help with e.f.   code first

    i got this error

    The column name 'PresupuestoDetalle_MS_Detalle_Presupuesto_Id' is invalid

    i got this class

    [Table("PRESUPUESTO")]
        public class PresupuestoEN
        {
            [Key]
            [Column("Presupuesto_Id")]
            public int MS_Presupuesto_Id { get; set; }
            [Column("V_NumPresupuesto")]
            public string NumPresupuesto { get; set; }
            [Column("F_Presupuesto")]
            public DateTime FechaPresupuesto { get; set; }
            [Column("R_SubTotal")]
            public float SubTotal { get; set; }
            [Column("R_IGV")]
            public float IGV { get; set; }
            [Column("R_Total")]
            public float Total { get; set; }
            [Column("Estado_Id")]
            public int Estado { get; set; }
            public virtual EstadoEN EstadoEntity { get; set; }
    
            [Column("V_UsuarioRegistro")]
            public string UsuarioRegistro { get; set; }
            [Column("F_Registro")]
            public DateTime FechaRegistro { get; set; }
            [Column("V_UsuarioModifico")]
            public string UsuarioModifico { get; set; }
            [Column("F_Modifico")]
            public DateTime FechaModifico { get; set; }
    
            [Column("Informe_Accidente_Id")]
            public int MS_Informe_Accidente_Id { get; set; }
    
        
            public virtual InformeAccidenteEN InformeAccidente { get; set; }
    
           public virtual ICollection<DetallePresupuestoEN> DetallePresupuesto { get; set; }
    
    
        public virtual DetallePresupuestoEN PresupuestoDetalle { get; set; }

    and the detail

        [Table("PRESUPUESTO_DETALLE")]
        public class DetallePresupuestoEN
        {
            [Key]
            [Column("Presupuesto_Detalle_Id")]
            public int MS_Detalle_Presupuesto_Id { get; set; }
            [Column("R_Importe")]
            public float Importe { get; set; }
            [Column("R_Descuento")]
            public float Descuento { get; set; }
            [Column("V_Observacion")]
            public string Observacion { get; set; }
            [Column("Presupuesto_Id")]
            public int MS_Presupuesto_Id { get; set; }
    
            [Column("Lista_Precio_Id")]
            public int MS_Lista_Precio_Id { get; set; }
            public virtual ListaPrecioEN ListaPrecio { get; set; }
        }
    }

    but I notice that DetallePresupuestoEN is a class but is trying to return like a field more, so the error, but I do not understand why

    according whit the trace in sql

    SELECT 
    [Extent1].[Presupuesto_Id] AS [Presupuesto_Id], 
    [Extent1].[V_NumPresupuesto] AS [V_NumPresupuesto], 
    [Extent1].[F_Presupuesto] AS [F_Presupuesto], 
    [Extent1].[R_SubTotal] AS [R_SubTotal], 
    [Extent1].[R_IGV] AS [R_IGV], 
    [Extent1].[R_Total] AS [R_Total], 
    [Extent1].[Estado_Id] AS [Estado_Id], 
    [Extent1].[V_UsuarioRegistro] AS [V_UsuarioRegistro], 
    [Extent1].[F_Registro] AS [F_Registro], 
    [Extent1].[V_UsuarioModifico] AS [V_UsuarioModifico], 
    [Extent1].[F_Modifico] AS [F_Modifico], 
    [Extent1].[Informe_Accidente_Id] AS [Informe_Accidente_Id], 
    [Extent1].[PresupuestoDetalle_MS_Detalle_Presupuesto_Id] AS [PresupuestoDetalle_MS_Detalle_Presupuesto_Id]
    FROM [dbo].[PRESUPUESTO] AS [Extent1]



    • Edited by Augusto C Monday, January 26, 2015 10:41 PM
    Monday, January 26, 2015 10:07 PM

Answers

  • Hello,

    According to your provided entities, I created a test and tried to reproduce this issue, however, the database is created successfully, I am not sure if this is because I comment out some properties because I do not know how to define them, here is tested demo:

    public class MyContext : DbContext
    
        {
    
            public MyContext()
    
            {
    
    
            }
    
            public DbSet<PresupuestoEN> PresupuestoENs { get; set; }
    
            public DbSet<DetallePresupuestoEN> DetallePresupuestoENs { get; set; }
    
        }
    
        [Table("PRESUPUESTO")]
    
        public class PresupuestoEN
    
        {
    
            [Key]
    
            [Column("Presupuesto_Id")]
    
            public int MS_Presupuesto_Id { get; set; }
    
            [Column("V_NumPresupuesto")]
    
            public string NumPresupuesto { get; set; }
    
            [Column("F_Presupuesto")]
    
            public DateTime FechaPresupuesto { get; set; }
    
            [Column("R_SubTotal")]
    
            public float SubTotal { get; set; }
    
            [Column("R_IGV")]
    
            public float IGV { get; set; }
    
            [Column("R_Total")]
    
            public float Total { get; set; }
    
            [Column("Estado_Id")]
    
            public int Estado { get; set; }
    
            //public virtual EstadoEN EstadoEntity { get; set; }
    
    
            [Column("V_UsuarioRegistro")]
    
            public string UsuarioRegistro { get; set; }
    
            [Column("F_Registro")]
    
            public DateTime FechaRegistro { get; set; }
    
            [Column("V_UsuarioModifico")]
    
            public string UsuarioModifico { get; set; }
    
            [Column("F_Modifico")]
    
            public DateTime FechaModifico { get; set; }
    
    
            [Column("Informe_Accidente_Id")]
    
            public int MS_Informe_Accidente_Id { get; set; }
    
            //public virtual InformeAccidenteEN InformeAccidente { get; set; }
    
            public virtual ICollection<DetallePresupuestoEN> DetallePresupuesto { get; set; }
    
            public virtual DetallePresupuestoEN PresupuestoDetalle { get; set; }
    
        }
    
        [Table("PRESUPUESTO_DETALLE")]
    
        public class DetallePresupuestoEN
    
        {
    
            [Key]
    
            [Column("Presupuesto_Detalle_Id")]
    
            public int MS_Detalle_Presupuesto_Id { get; set; }
    
            [Column("R_Importe")]
    
            public float Importe { get; set; }
    
            [Column("R_Descuento")]
    
            public float Descuento { get; set; }
    
            [Column("V_Observacion")]
    
            public string Observacion { get; set; }
    
            [Column("Presupuesto_Id")]
    
            public int MS_Presupuesto_Id { get; set; }
    
    
            [Column("Lista_Precio_Id")]
    
            public int MS_Lista_Precio_Id { get; set; }
    
            //public virtual ListaPrecioEN ListaPrecio { get; set; }
    
    }
    


    The tested environment is VS2013, EF6 code first and windows 8.1. Please have a try with it and this would help narrow down this issue to see if it is caused by the two entities you currently provide.

    If it does not work for you, please share detail tables so that we can make exact test.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Wednesday, February 11, 2015 1:32 AM
    Wednesday, January 28, 2015 3:31 AM

All replies

  • Hello,

    According to your provided entities, I created a test and tried to reproduce this issue, however, the database is created successfully, I am not sure if this is because I comment out some properties because I do not know how to define them, here is tested demo:

    public class MyContext : DbContext
    
        {
    
            public MyContext()
    
            {
    
    
            }
    
            public DbSet<PresupuestoEN> PresupuestoENs { get; set; }
    
            public DbSet<DetallePresupuestoEN> DetallePresupuestoENs { get; set; }
    
        }
    
        [Table("PRESUPUESTO")]
    
        public class PresupuestoEN
    
        {
    
            [Key]
    
            [Column("Presupuesto_Id")]
    
            public int MS_Presupuesto_Id { get; set; }
    
            [Column("V_NumPresupuesto")]
    
            public string NumPresupuesto { get; set; }
    
            [Column("F_Presupuesto")]
    
            public DateTime FechaPresupuesto { get; set; }
    
            [Column("R_SubTotal")]
    
            public float SubTotal { get; set; }
    
            [Column("R_IGV")]
    
            public float IGV { get; set; }
    
            [Column("R_Total")]
    
            public float Total { get; set; }
    
            [Column("Estado_Id")]
    
            public int Estado { get; set; }
    
            //public virtual EstadoEN EstadoEntity { get; set; }
    
    
            [Column("V_UsuarioRegistro")]
    
            public string UsuarioRegistro { get; set; }
    
            [Column("F_Registro")]
    
            public DateTime FechaRegistro { get; set; }
    
            [Column("V_UsuarioModifico")]
    
            public string UsuarioModifico { get; set; }
    
            [Column("F_Modifico")]
    
            public DateTime FechaModifico { get; set; }
    
    
            [Column("Informe_Accidente_Id")]
    
            public int MS_Informe_Accidente_Id { get; set; }
    
            //public virtual InformeAccidenteEN InformeAccidente { get; set; }
    
            public virtual ICollection<DetallePresupuestoEN> DetallePresupuesto { get; set; }
    
            public virtual DetallePresupuestoEN PresupuestoDetalle { get; set; }
    
        }
    
        [Table("PRESUPUESTO_DETALLE")]
    
        public class DetallePresupuestoEN
    
        {
    
            [Key]
    
            [Column("Presupuesto_Detalle_Id")]
    
            public int MS_Detalle_Presupuesto_Id { get; set; }
    
            [Column("R_Importe")]
    
            public float Importe { get; set; }
    
            [Column("R_Descuento")]
    
            public float Descuento { get; set; }
    
            [Column("V_Observacion")]
    
            public string Observacion { get; set; }
    
            [Column("Presupuesto_Id")]
    
            public int MS_Presupuesto_Id { get; set; }
    
    
            [Column("Lista_Precio_Id")]
    
            public int MS_Lista_Precio_Id { get; set; }
    
            //public virtual ListaPrecioEN ListaPrecio { get; set; }
    
    }
    


    The tested environment is VS2013, EF6 code first and windows 8.1. Please have a try with it and this would help narrow down this issue to see if it is caused by the two entities you currently provide.

    If it does not work for you, please share detail tables so that we can make exact test.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Wednesday, February 11, 2015 1:32 AM
    Wednesday, January 28, 2015 3:31 AM
  • hi

    thanks for your answer

    With which code is executing the query?

    Friday, January 30, 2015 7:24 PM
  • Hello,

    >> With which code is executing the query?

    It looks like below:

    db.Database.CreateIfNotExists();
    
    db.Database.Log = Console.Write;
    
    var result = db.PresupuestoENs.ToList();
    

    The generated sql statement:

    It returns the data correctly, please have a try with my demo and if it works, I am wondering this exception is caused by other entities.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 2, 2015 9:35 AM