EF代码第一个属性未映射

时间:2011-12-27 15:36:12

标签: entity-framework entity-framework-4.1

我遇到的问题是当我尝试在ASPxGridView中插入新记录时,它是asp.net页面中的详细信息的主人。

只有在没有记录时才需要添加新记录时才会出现这种情况。

EnderecoEscola实体:

namespace DAL
{
  [Table("CAD_ENDERECO_ESCOLA")]
  public class EnderecoEscola
  {
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ENDESC_ID { get; set; }

    [Required]
    public int ESCOLA_ID { get; set; }

    [Association("Escolas", "ESCOLA_ID", "ESCOLA_ID")]
    [ForeignKey("ESCOLA_ID")]
    public virtual Escola Escola { get; set; }

    [Required]
    public int TPOEND_ID { get; set; }

    [ForeignKey("TPOEND_ID")]
    public virtual TipoEndereco TipoEndereco { get; set; }

    [Required]
    public int ENDESC_UF_ID { get; set; }

    [ForeignKey("ENDESC_UF_ID")]
    public virtual UnidadeFederativa UnidadeFederativa { get; set; }

    [Required]
    public int ENDESC_MUN_iD { get; set; }

    [ForeignKey("ENDESC_MUN_iD")]
    public virtual Municipio Municipio { get; set; }

    [StringLength(10), Required]
    [MinLength(8)]
    public string ENDESC_CEP { get; set; }

    [StringLength(100), Required]
    [MinLength(10)]
    public string ENDESC_ENDERECO { get; set; }

    [StringLength(15)]
    public string ENDESC_NRO { get; set; }

    [StringLength(25)]
    public string ENDESC_COMPL { get; set; }

    [StringLength(70)]
    public string ENDESC_BAIRRO { get; set; }

    [NotMapped]
    public String TPEND_DESCRICAO { get; set; }

    [NotMapped]
    public String UF_SIGLA { get; set; }

    [NotMapped]
    public String MUN_DESCRICAO { get; set; }

  }
}

DAL:

namespace DAL.utilities
{
  public class OperationCadEnderecoEscola
  {
    public IQueryable<EnderecoEscola> GetId(int idEsc)
    {
      using (SecurityCtx ctx = new SecurityCtx())
      {
        ctx.Configuration.LazyLoadingEnabled = false;
        var query = ctx.EnderecoEscola.Include("TipoEndereco").Include("UnidadeFederativa").Include("Municipio").Where(w => w.ESCOLA_ID == idEsc).OrderBy(p => p.ENDESC_ENDERECO).ToList().
            Select(w => new EnderecoEscola
            {
              ENDESC_ID = w.ENDESC_ID,
              ESCOLA_ID = w.ESCOLA_ID,
              TPOEND_ID = w.TPOEND_ID,

              ENDESC_UF_ID = w.ENDESC_UF_ID,
              ENDESC_MUN_iD = w.ENDESC_MUN_iD,
              ENDESC_CEP = w.ENDESC_CEP,

              ENDESC_ENDERECO = w.ENDESC_ENDERECO,
              ENDESC_NRO = w.ENDESC_NRO,
              ENDESC_COMPL = w.ENDESC_COMPL,
              ENDESC_BAIRRO = w.ENDESC_BAIRRO,

              TPEND_DESCRICAO = w.TipoEndereco.TPEND_DESCRICAO != null ?  w.TipoEndereco.TPEND_DESCRICAO : w.TPEND_DESCRICAO,
              UF_SIGLA        = w.UnidadeFederativa.UF_SIGLA != null ?  w.UnidadeFederativa.UF_SIGLA : w.UF_SIGLA,
              MUN_DESCRICAO   = w.Municipio.MUN_DESCRICAO != null ?  w.Municipio.MUN_DESCRICAO : w.MUN_DESCRICAO

            }).Distinct().AsQueryable();

        return query;
      }
    }
  }
}

当申请包含在ASPxGridView中时,新的记录和DAL public IQueryable <EnderecoEscola> getId (int idEsc)中的方法被调用来检索数据并且它们不存在它会在主数据上添加新记录并且发生详细信息错误

  

在。中找不到名称为“TPEND_DESCRICAO”的字段或属性   选定的数据来源。

有人可以指导我如何解决问题。

韩国社交协会

0 个答案:

没有答案