doubts with linq to entities

1

What would be the query in linq to entities:

SELECT      COUNT(cont) qtde_resp
        ,   pergunta
        ,   resposta
FROM        pesq_respostas
WHERE       id_pesquisa = 9
        AND Tipo IN ('Intervalo', 'SimNao')
GROUP BY    pergunta
        ,   resposta

I tried to do this:

dynamic countTag = (from a in context.PesqRespostaModel
                                    where a.id_pesquisa == idPesquisa
                                    group new { a } by new {  a.resposta, a.pergunta } into gr
                                    select new
                                    {
                                        gr.Key.pergunta,
                                        gr.Key.resposta,
                                        Count = gr.Select(x => x.a.cpf).Distinct().Count()

                                    }).ToList();

but gives the following error:

Butthisfieldexists,bothinthebankandintheclass.

Followmytemplate:

[Table("pesq_respostas")]
public class PesqRespostaModel
{
    [Key]
    [Required]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int id_resposta { get; set; }

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

    [Required]
    [Display(Name = "pergunta")]
    [StringLength(128, ErrorMessage = "O campo Resposta pode ter mo máximo 128 caracteres.")]
    public string pergunta { get; set; }

    [Required]
    [Display(Name = "resposta")]
    [StringLength(48, ErrorMessage = "O campo Resposta pode ter mo máximo 48 caracteres.")]
    public string resposta { get; set; }

    public string tipo { get; set; }

    [Required]
    [Display(Name = "cpf")]
    [StringLength(14, ErrorMessage = "O campo Resposta pode ter mo máximo 14 caracteres.")]
    public string cpf { get; set; }            

    [Required]
    [Display(Name = "data")]        
    public DateTime data { get; set; }
}
    
asked by anonymous 06.12.2018 / 18:45

0 answers