Npgsql and EF error (42703) - column does not exist

2,934 views
Skip to first unread message

Gustavo Adolfo A. S.

unread,
Jun 10, 2014, 9:12:27 AM6/10/14
to npgsq...@googlegroups.com
I'm use Npgsql version 2.1.3.0 and everything was working fine until this error started happening today and I can not find the reason for this.

(column does not exist)    InnerException {"ERRO: 42703: coluna Extent1.Planos_Id não existe"} System.Exception {Npgsql.NpgsqlException}


This is the code generated by Npgsql

    select 'Npgsql12322'
    (easylabweb%::1(64263)%42700%74)ERRO:  coluna Extent1.Planos_Id não existe no caracter 142
    (easylabweb%::1(64263)%42700%74)COMANDO:  SELECT "Extent1"."id" AS "id","Extent1"."exame_id" AS "exame_id","Extent1"."plano_id" AS "plano_id","Extent1"."convenio_id" AS "convenio_id","Extent1"."Planos_Id" AS "Planos_Id" FROM "public"."descoberto" AS "Extent1" WHERE ("Extent1"."Planos_Id" IS NOT NULL ) AND ("Extent1"."Planos_Id"= (((5179))))
    (easylabweb%::1(64263)%00000%74)LOG:  duração: 0.000 ms  comando: DISCARD ALL
    (easylabweb%::1(64263)%00000%74)LOG:  duração: 0.000 ms  comando: SET extra_float_digits=3;

Really, Planos_Id does not exists!

This is my model:

    [Serializable]
    [Table(name:"descoberto", Schema= "public")]
    public class ExmDescobertos
    {
        public ExmDescobertos()
        {
            var bytes = Identificador.ToByteArray();
            if (!bytes.Any(b => b != 0))
                Identificador = Guid.NewGuid();
        }

        [NotMapped]
        public Guid Identificador { get; private set; }

        [Key, Column("id")]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Column("exame_id")]
        public int ExameId { get; set; }

        [ForeignKey("ExameId")]
        public virtual Exames Exame { get; set; }

        [Column("plano_id")]
        public int PlanoId { get; set; }

        [Column("convenio_id")]
        public int ConvenioId { get; set; }
    }

Thanks for your help

Josh Cooley

unread,
Jun 10, 2014, 11:48:35 AM6/10/14
to Gustavo Adolfo A. S., npgsql-help
Can you post the query that generated this SQL as well?


--
You received this message because you are subscribed to the Google Groups "Npgsql Help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to npgsql-help...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/npgsql-help/1aba7072-a2c3-4a4a-8a45-70f224bddb58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gustavo Adolfo A. S.

unread,
Jun 11, 2014, 8:32:06 AM6/11/14
to npgsq...@googlegroups.com, gustavo....@gmail.com
Thanks friend. 
No query specific. I have cleaned the solution, recreated the properties of models and recompiled all. Now, works fine. (?????)

Gustavo Adolfo A. S.

unread,
Jun 13, 2014, 10:40:16 AM6/13/14
to npgsq...@googlegroups.com, gustavo....@gmail.com
The problem persisting occasionaly.  Occurs when I try a insert.
Do anyone have any idea?

{"An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types. See the InnerException for details."}

InnerException = ERRO: 42703: coluna "Convenios_Id" da relação "plano" não existe

My properties for relationship:

//Convenio Model

[Table(name: "convenio", Schema = "public")]
[Serializable]
public class Convenios
{       
    [Key, Column("id")]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    public virtual ICollection<Planos> ListaPlanos { getset; }

    /* ... */
}

/* MOdel Planos */

[Table(name: "plano", Schema = "public")]
[Serializable]
public class Planos
{

    [Key, Column("id")]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    [Column("convenio_id")]
    [Required(ErrorMessage = "É preciso vincular um convênio a este plano")]
    public int ConvenioId { get; set; }
 
    [ForeignKey("ConvenioId")]
    public virtual Convenios ConvenioVinculado { get; set; }

    /* ... */

}

This is a query generated by Npgsql/Entity Framework:

(easylabweb%::1(3379)%42700%74)ERRO:  coluna "Convenios_Id" da relação "plano" não existe no caracter 421
(easylabweb%::1(3379)%42700%74)COMANDO:  INSERT INTO "public"."plano"("convenio_id","descricao","codigo","tabela_id","padrao","percpac","percconv","banda_porte","banda_uco","valch","usuario","status","valfilme","codfilme","codigofilm","motivo","limite","mpercconv","mpercpac","fpercpac","fpercconv","autoriza","deparapla","valorauto","autori","ambobriga","descmat","obs","tipotab","valcopart","dtultger","operador_id_ultger","marca","dtultgerini","dtultgerfin","Convenios_Id") VALUES (0,E'Qui et eum soluta sed et expedita',NULL,cast(177 as int8),1,25,75,35,65,cast(30 as numeric),NULL,0,NULL,NULL,NULL,NULL,8,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,NULL,NULL,E'Eos, modi deserunt beatae et eveniet, mollitia omnis voluptate nulla eiusmod labore.',2,61,NULL,NULL,NULL,NULL,NULL,cast(5143 as int8));

SELECT currval(pg_get_serial_sequence('"public"."plano"', 'id')) AS "id"
(easylabweb%::1(3379)%00000%74)LOG:  duração: 0.000 ms  comando: ROLLBACK

I don't have idea about this problem... 
Reply all
Reply to author
Forward
0 new messages