2
I am using the following code to bring a list of companies with CNPJ formatted for Datagridview:
dgv.DataSource = db.pessoajuridica
                   .Select(d => new { d.idPessoa, d.nome, d.cnpj })
                   .AsEnumerable()
                   .Select(c => new { IdPessoa = c.idPessoa, Razão = c.nome, CNPJ = Convert.ToUInt64(c.cnpj).ToString(@"00\.000\.000\/0000\-00") })
                   .ToList();
And I’m using the following code to bring a list of individuals and legal entities to Datagridview:
dgv.DataSource = db.pessoajuridica
                   .Select(m => new { IdCliente = m.idPessoa, Nome = m.nome, Tipo = "Pessoa Jurídica", Documento = m.cnpj })
                   .Concat(db.pessoafisica
                   .Select(m => new { IdCliente = m.idPessoa, Nome = m.nome,  Tipo = "Pessoa Física", Documento = m.cpf }))
                   .ToList();
But I would like this second option to also come with formatting, one specific for CNPJ and another specific for CPF. But it’s not working...
The classes are defined below:
[Table("pessoa")]
public class pessoa
{
    [Key]
    public int idPessoa { get; set; }
    [Required]
    [StringLength(90)]
    public string nome { get; set; }
}
[Table("pessoafisica")]
public class pessoafisica : pessoa
{
    [StringLength(11)]
    public string cpf { get; set; }
    [StringLength(20)]
    public string rg { get; set; }
}
[Table("pessoajuridica")]
public class pessoajuridica : pessoa
{
    [StringLength(15)]
    public string cnpj { get; set; }
    [StringLength(255)]
    public string nomeFantasia { get; set; }
}
Does anyone know how I could do?
Thanks!!!
Why don’t you use the
.ToString()as you did in the other query?– Jéf Bueno
Because I can’t use . Tostring() inside the query... so I put . Asenumerable() and in the next select I used . Tostring()
– Felipe Bulle