How to insert a where inside a linq query

1

I have the following query :

var result = (from line in db.ApadrinhamentoListas
    group new { line } by new { line.datahora, line.valor_doacao } 
    into grp 
    select new 
    {
      DataHora = grp.Key.datahora,
      Valor = grp.Key.valor_doacao
    }).OrderBy(o => o.DataHora);

And I would like to put a where in the middle of this to pull the values just from a specific cnpj. In case this query returns all the sponsorship that is registered in the database, but I would like it to return from the specific node that is logged, in the database I have the field ong_receptora , which has the cnpj of the same, and I can also retrieve cnpj from the logged ong, but I do not know how to make such a comparison in query .

    
asked by anonymous 29.11.2017 / 21:11

2 answers

2

It is simple to just create the variable with the value of CNPJ and make a Where , same example below:

var cnpj = "valor do cnpj";
var result = (from line in db.ApadrinhamentoListas where line.ong_receptora == cnpj
    group new { line } by new { line.datahora, line.valor_doacao } 
    into grp 
    select new 
    {
      DataHora = grp.Key.datahora,
      Valor = grp.Key.valor_doacao
    }).OrderBy(o => o.DataHora);
    
29.11.2017 / 21:21
2
var result = (from line in db.ApadrinhamentoListas
    where line.ong_receptora == "valor"
    group new { line } by new { line.datahora, line.valor_doacao } 
    into grp 
    select new 
    {
      DataHora = grp.Key.datahora,
      Valor = grp.Key.valor_doacao
    }).OrderBy(o => o.DataHora);

or

 var result = (from line in db.ApadrinhamentoListas.
        where(x=>x.ong_receptora.equals("valor"))
        group new { line } by new { line.datahora, line.valor_doacao } 
        into grp 
        select new 
        {
          DataHora = grp.Key.datahora,
          Valor = grp.Key.valor_doacao
        }).OrderBy(o => o.DataHora);
    
29.11.2017 / 21:21