How to insert a Where into a Linux query

Asked

Viewed 126 times

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’d like to put one Where in the middle of this to pull the values only from a specific cnpj. In this case this query returns all sponsorships that are registered in the bank, but I would like you to return from the specific Ong that is logged in, in the bank have the field ong_receptora, that has the cnpj of the same, and I can also retrieve the cnpj of the logged Ong, but I do not know how to make such a comparison in the query.

  • the cnpj is inside ApadrinhamentoListas ?

  • 1

    In Sponsorentolists I have the ong_receptor field, which has the cnpj of Ong, and through a method I can get the cnpj of Ong logged in.

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);

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);

Browser other questions tagged

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