title: Entity Framework 4,1 code first, error The specified type member ENDESC_CEP is not supported in LINQ to Entities
body: <p>I am using Entity Framework 4.1 code first, to perform the search below returns me the error message: The specified type member ENDESC_CEP is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported., This occurs while the parameter qunado SCEP.
     Even when the parameter SCEP step the address data are not loaded.
      Would anyone tell me what should I do?
   I appreciate any help.</p>
  
  <pre><code>using (SecurityCtx ctx = new SecurityCtx())
      {
        ctx.Configuration.LazyLoadingEnabled = true;
        var query = ctx.Escola.Include("UnidadeFederativa").Include("Municipio").Include("EnderecoEscolas").Where(p =&gt; p.ID_EMPRESA == IdEmpresa);
  
        if ( (!String.IsNullOrEmpty(sUF) ) &amp;&amp; (sUF != "ZZ") )
        {
          query = query.Where(p =&gt; p.UnidadeFederativa.UF_SIGLA == sUF);
        }
  
        if (!String.IsNullOrEmpty(sMunicipio))
        {
          query = query.Where(p =&gt; p.Municipio.MUN_DESCRICAO.Contains(sMunicipio.Trim()));
        }
  
        if ( ! String.IsNullOrEmpty( sNome ) )
        {
          query = query.Where(p =&gt; p.ESCOLA_NOME.Contains(sNome.Trim()));
        }
  
        if ( ! String.IsNullOrEmpty( sCodigo) )
        {
          query = query.Where(p =&gt; p.ESCOLA_CODIGO.Contains(sCodigo.Trim()));
        }
  
        if (!String.IsNullOrEmpty(sEndereco))
        {
          query = query.Where(p =&gt; p.EnderecoEscolas.ToList().Select( item =&gt; item.ENDESC_ENDERECO.Contains( sEndereco.Trim() ) ).First() );
        }
  
        if (!String.IsNullOrEmpty(sBairro))
        {
          query = query.Where(p =&gt; p.EnderecoEscolas.ToList().Select( item =&gt; item.ENDESC_BAIRRO.Contains( sBairro.Trim() ) ).First() );
        }
  
        if (!String.IsNullOrEmpty(sCEP))
        {
          query = query.Where(p =&gt; p.ENDESC_CEP.Contains(sCEP) );
        }
  
        query = query.OrderBy( p =&gt;  p.ESCOLA_NOME.Trim()  ).ToList().Select(item =&gt; new Escola
            {
              ESCOLA_ID = item.ESCOLA_ID,
              ID_EMPRESA = item.ID_EMPRESA,
              ESCOLA_CODIGO = item.ESCOLA_CODIGO,
              ESCOLA_NOME   = item.ESCOLA_NOME,
              ESCOLA_CNPJ   = item.ESCOLA_CNPJ,
              ESCOLA_E_MAIL = item.ESCOLA_E_MAIL,
              ESCOLA_URL    = item.ESCOLA_URL,
              ESCOLA_NOME_FANTASIA = item.ESCOLA_NOME_FANTASIA,
              ESCOLA_UF_ID         = item.ESCOLA_UF_ID,
              ESCOLA_MUNICIPIO_ID  = item.ESCOLA_MUNICIPIO_ID,
              ESCOLA_REDE_ID       = item.ESCOLA_REDE_ID,
              ESCOLA_LOCAL_ID      = item.ESCOLA_LOCAL_ID,
              STATUS_MUNICIPIO_ID  = item.STATUS_MUNICIPIO_ID,
              CODIGO_NIVEL_SE_ID   = item.CODIGO_NIVEL_SE_ID,
              CODIGO_PER_PLA_DIDATICO_ID = item.CODIGO_PER_PLA_DIDATICO_ID,
              CODIGO_PER_PLA_PARADIDATICO_ID = item.CODIGO_PER_PLA_PARADIDATICO_ID,
              ESCOLA_ORIGEM_DADOS_ID         = item.ESCOLA_ORIGEM_DADOS_ID,
              ESCOLA_ATIVA                   = item.ESCOLA_ATIVA,
              ESCOLA_DATA_CADASTRAMENTO      = item.ESCOLA_DATA_CADASTRAMENTO,
              ESCOLA_DATA_ATUALIZACAO        = item.ESCOLA_DATA_ATUALIZACAO,
              UF_SIGLA                       = item.UnidadeFederativa.UF_SIGLA,
              UF_DESCRICAO                   = item.UnidadeFederativa.UF_DESCRICAO,
              MUN_DESCRICAO                  = item.Municipio.MUN_DESCRICAO,
              ENDESC_ENDERECO                = item.ENDESC_ENDERECO,
              ENDESC_NRO                     = item.ENDESC_NRO,
              ENDESC_CEP                     = item.ENDESC_CEP , 
              ENDESC_COMPL                   = item.ENDESC_COMPL , 
              ENDESC_BAIRRO                  = item.ENDESC_BAIRRO 
            }).AsQueryable();
  
        return query;
  </code></pre>
  
  <p>DAO :</p>
  
  <pre><code>[Table("CAD_ESCOLAS")]
    public class Escola
    {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int ESCOLA_ID { get; set; }
  
      [Required]
      public int ID_EMPRESA { get; set; }
  
      [ForeignKey("ID_EMPRESA")]
      public virtual Empresa Empresa { get; set; }
  
      [StringLength(10), Required]
      [MinLength(8)]
      public string ESCOLA_CODIGO { get; set; }
  
      [StringLength(120), Required]
      [MinLength(20)]
      public string ESCOLA_NOME { get; set; }
  
      [StringLength(20)]
      public string ESCOLA_CNPJ { get; set; }
  
      [StringLength(120)]
      public string ESCOLA_E_MAIL { get; set; }
  
      [StringLength(120)]
      public string ESCOLA_URL { get; set; }
  
      [StringLength(80)]
      public string ESCOLA_NOME_FANTASIA { get; set; }
  
      [Required]
      public int ESCOLA_UF_ID { get; set; }
  
      [ForeignKey("ESCOLA_UF_ID")]
      public virtual UnidadeFederativa UnidadeFederativa { get; set; }
  
      [Required]
      public int ESCOLA_MUNICIPIO_ID { get; set; }
  
      [ForeignKey("ESCOLA_MUNICIPIO_ID")]
      public virtual Municipio Municipio { get; set; }
  
      [Required]
      public int ESCOLA_REDE_ID { get; set; }
  
      [ForeignKey("ESCOLA_REDE_ID")]
      public virtual RedeEnsino RedeEnsino { get; set; }
  
      [Required]
      public int ESCOLA_LOCAL_ID { get; set; }
  
      [ForeignKey("ESCOLA_LOCAL_ID")]
      public virtual TipoLocalizacao TipoLocalizacao { get; set; }
  
      [Required]
      public int STATUS_MUNICIPIO_ID { get; set; }
  
      [ForeignKey("STATUS_MUNICIPIO_ID")]
      public virtual StatusMunicipio StatusMunicipio { get; set; }
  
      [Required]
      public int CODIGO_NIVEL_SE_ID { get; set; }
  
      [ForeignKey("CODIGO_NIVEL_SE_ID")]
      public virtual NivelSocioEconomico NivelSocioEconomico { get; set; }
  
      [Required]
      public int CODIGO_PER_PLA_DIDATICO_ID { get; set; }
  
      [ForeignKey("CODIGO_PER_PLA_DIDATICO_ID")]
      public virtual PerPlanDidatico PerPlanDidatico { get; set; }
  
      [Required]
      public int CODIGO_PER_PLA_PARADIDATICO_ID { get; set; }
  
      [ForeignKey("CODIGO_PER_PLA_PARADIDATICO_ID")]
      public virtual PerPlanParadidatico PerPlanParadidatico { get; set; }
  
      [Required]
      public int ESCOLA_ORIGEM_DADOS_ID { get; set; }
  
      [ForeignKey("ESCOLA_ORIGEM_DADOS_ID")]
      public virtual OrigemDadosEsc OrigemDadosEsc { get; set; }
  
      [Required]
      public bool ESCOLA_ATIVA { get; set; }
  
      [Required]
      public DateTime ESCOLA_DATA_CADASTRAMENTO { get; set; }
  
      [Required]
      public DateTime ESCOLA_DATA_ATUALIZACAO { get; set; }
  
      [NotMapped]
      public String UF_SIGLA { get; set; }
  
      [NotMapped]
      public String UF_DESCRICAO { get; set; }
  
  
      [NotMapped]
      public String MUN_DESCRICAO { get; set; }
  
      [NotMapped]
      public String ENDESC_ENDERECO { get; set; }
  
      [NotMapped]
      public String ENDESC_NRO { get; set; }
  
      [NotMapped]
      public String ENDESC_CEP { get; set; }
  
      [NotMapped]
      public String ENDESC_COMPL { get; set; }
  
      [NotMapped]
      public String ENDESC_BAIRRO { get; set; }
  
      public virtual ICollection&lt;EnderecoEscola&gt; EnderecoEscolas { get; set; }
  
      public Escola()
      {
         EnderecoEscolas = new HashSet&lt;EnderecoEscola&gt;();
      }
  
    }
  
  
  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; }
  
      [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; }
  
    }
  }
  </code></pre>
  
  <p>Tks</p>
  
  <hr>
  
  <p>I need to present data in a Grid entity's School and entities related to it, ie UnidadeFederativa, Municipio and EscolaEnderecos, as in the select below:</p>
  
  <pre><code>select a.ESCOLA_NOME, 
         c.UF_SIGLA,
         d.MUN_DESCRICAO,
         b.ENDESC_ENDERECO, 
         b.ENDESC_BAIRRO
     from CAD_ESCOLAS a,
          CAD_ENDERECO_ESCOLA b,
          CAD_UNIDADE_FEDERATIVA c,
          CAD_MUNICIPIO          d
     where a.ESCOLA_UF_ID = c.UF_ID and
           a.ESCOLA_MUNICIPIO_ID = d.MUN_ID and
           b.ESCOLA_ID = a.ESCOLA_ID and
           b.ENDESC_CEP like '03138%'
  order by 1
  </code></pre>
  
  <p>I use the properties [notmapped] only in order to present the same data record returned from the various related entities.</p>
  
  <p>The fact is that I can not access the properties of the entity EscolaEnderecos, Where to apply the condition, I can bring in recovering data EscolaEnderecos, only the first record and not all that satifizerem WHERE clauses, as follows:</p>
  
  <pre><code> item.EnderecoEscolas.Select (p =&gt; p.ENDESC_ENDERECO). First ()
  </code></pre>
  
  <p>In short I can not, in the clause, Where EnderecoEscola access the property and also can not bring EnderecoEscola data for each record returned from the School Entity.</p>
  
  <p>If someone can guide me I am very grateful.</p>
  
  <p>Tks</p>
  
  <p>I need to present data in a Grid entity's School and entities related to it, ie UnidadeFederativa, Municipio and EscolaEnderecos, as in the select below:</p>
  
  <pre><code>select a.ESCOLA_NOME,  
         c.UF_SIGLA, 
         d.MUN_DESCRICAO, 
         b.ENDESC_ENDERECO,  
         b.ENDESC_BAIRRO 
     from CAD_ESCOLAS a, 
          CAD_ENDERECO_ESCOLA b, 
          CAD_UNIDADE_FEDERATIVA c, 
          CAD_MUNICIPIO          d 
     where a.ESCOLA_UF_ID = c.UF_ID and 
           a.ESCOLA_MUNICIPIO_ID = d.MUN_ID and 
           b.ESCOLA_ID = a.ESCOLA_ID and 
           b.ENDESC_CEP like '03138%' 
  order by 1 
  </code></pre>
  
  <p>I use the properties [notmapped] only in order to present the same data record returned from the various related entities.</p>
  
  <p>The fact is that I can not access the properties of the entity EscolaEnderecos, Where to apply the condition, I can bring in recovering data EscolaEnderecos, only the first record and not all that satifizerem WHERE clauses, as follows:
   item.EnderecoEscolas.Select (p => p.ENDESC_ENDERECO). First () </p>
  
  <p>In short I can not, in the clause, Where EnderecoEscola access the property and also can not bring EnderecoEscola data for each record returned from the School Entity.</p>
  
  <p>If someone can guide me I am very grateful.</p>
  
  <p>Tks</p>