Npgsql和EF错误(42703) - 列不存在(一对多关系)

时间:2017-12-13 18:48:59

标签: c# entity-framework-6 npgsql

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

  

“保存未公开其关系的外键属性的实体时发生错误.EntityEntries属性将返回null,因为无法将单个实体标识为异常的来源。保存时可以更轻松地处理异常通过在实体类型中公开外键属性。有关详细信息,请参阅InnerException。“

     

InnerException = ERRO:42703:coluna“Convenios_Id”darelação“plano”nãoreiste

我的关系属性:

//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]
    public int ConvenioId { get; set; }

    [ForeignKey("ConvenioId")]
    public virtual Convenios ConvenioVinculado { get; set; }

    /* ... */

}

这是Npgsql/Entity Framework生成的查询:

  

错误:coluna“Convenios_Id”darelação“plano”nãoreisteno   caracter 421命令:INSERT INTO   “公”。 “平”( “convenio_id”, “descricao”, “codigo”, “tabela_id”, “padrao”, “percpac”, “percconv”, “banda_porte”, “banda_uco”, “valch”,“usuario ”, “状态”, “valfilme”, “codfilme”, “codigofilm”, “motivo”, “LIMITE”, “mpercconv”, “mpercpac”, “fpercpac”, “fpercconv”, “autoriza”, “deparapla” “valorauto”, “autori”, “ambobriga”, “descmat”, “OBS”, “tipotab”, “valcopart”, “dtultger”, “operador_id_ultger”, “马卡报”, “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   数字),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));

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

0 个答案:

没有答案