Lambda com List

Asked

Viewed 96 times

1

I have the classes:

public class Modulo
{
    [Key]
    public int ModuloID { get; set; }
    public int SatisfacaoID { get; set; }

    public virtual Satisfacao Satisfacao { get; set; }
    public virtual ICollection<AlunoSatisfacao> AlunoSatisfacoes { get; set; }
}

public class AlunoSatisfacao
{
    public int AlunoSatisfacaoID { get; set; }
    public DateTime Data { get; set; }
    public int SatisfacaoID { get; set; }
    public int AlunoID { get; set; }
    public int ModuloID { get; set; }

    public virtual Satisfacao Satisfacao { get; set; }
    public virtual Aluno Aluno { get; set; }
    public virtual Modulo Modulo { get; set; }
    public virtual ICollection<AlunoSatisfacaoResposta> AlunoSatisfacaoRespostas { get; set; }
}

public class AlunoSatisfacaoResposta
{
     [Key]
     public int AlunoSatisfacaoRespostaID { get; set; }
     public int AlunoSatisfacaoID { get; set; }
     public int SatisfacaoPerguntaID { get; set; }
     public string Resposta { get; set; }

     public virtual AlunoSatisfacao AlunoSatisfacao { get; set; }
     public virtual SatisfacaoPergunta SatisfacaoPergunta { get; set; }
}

Given a Modulo, I want to know how many AlunoSatisfacaoResposta has the resposta 2 and SatisfacaoPerguntaID 2.

Something like (I know that’s not possible):

var modulo = PegarModulo(5);
int countResposta = modulo.AlunoSatisfacao.Where(x=> x.AlunoSatisfacaoRespostas.Resposta = 2 && x.AlunoSatisfacaoRespostas.SatisfacaoPerguntaID = 2).Count();
  • You want to know who typed in the answer field the number 2 and the Question Id is 2, that’s right?

1 answer

2


int countResposta = modulo.AlunoSatisfacoes.Where(
                        x => x.AlunoSatisfacaoRespostas.Any(
                            y => y.Resposta == "2" && y.SatisfacaoPerguntaID == 2
                        )
                    ).Count();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.