Npgsql和EF错误(42703) - 列不存在

时间:2014-06-09 21:30:28

标签: asp.net-mvc entity-framework npgsql

****** ****** UPDATE

这个问题偶尔会持续存在。我尝试插入时发生。 有人有任何想法吗?

{"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”darelação“plano”nãorestiste

我的关系属性:

// 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 { get; set; }

    /* ... */
}

/ * 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; }

    /* ... */
}

这是由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

我对这个问题一无所知......

** END UPDATE **

我使用 Npgsql 版本2.1.3.0,一切正常,直到今天发生此错误,我找不到原因。

(列不存在)

InnerException  {"ERRO: 42703: coluna Extent1.Planos_Id não existe"}    System.Exception {Npgsql.NpgsqlException}

这是 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;

这是我的模特:

[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")]
    [Required(ErrorMessage = "Informe o exame")]
    public int ExameId { get; set; }

    [ForeignKey("ExameId")]
    [Display(Name = "Exame", Description = "Exame")]
    public virtual Exames Exame { get; set; }

    [Column("plano_id")]
    [Required(ErrorMessage = "Informe o plano")]
    public int PlanoId { get; set; }

    [Column("convenio_id")]
    [Required(ErrorMessage = "Informe o Convênio")]
    public int ConvenioId { get; set; }

感谢您的帮助

0 个答案:

没有答案