0

Something like this:

        Itens = db.Transacao.AsNoTracking()
            if (x == 1)
                .Where(w => w.Confirmado == true)
            else
                .Where(w => w.Data.Date >= DateTime.Now.Date)
            .Include(i => i.Pessoa)
            .Include(i => i.Categoria)
            .ToList();

I know that this don't exist, but, exist something similar to this?

1 Answer 1

2

Well, you can do something like this:

IQueryable<[your entity here]> query = db.Transacao.AsNoTracking();
if (x == 1)
    query = query.Where(w => w.Confirmado == true);
else
    query = query.Where(w => w.Data.Date >= DateTime.Now.Date);

return query.Include(i => i.Pessoa)
            .Include(i => i.Categoria)
            .ToList();

Hope it helps.

Sign up to request clarification or add additional context in comments.

3 Comments

When it is a table with few records I use this. But when there is a lot of records in the table we have problems. IQueryable<[your entity here]> query = db.Transacao.AsNoTracking(); Here we get all the records, and only after we filter they. If we could create the query first, and only in the end we Apply the query.
The query doesn't get executed until you call the .ToList() method, so you're not getting any records on the AsNoTracking() line, you're just building the query. Check this link learn.microsoft.com/en-us/ef/core/querying/how-query-works
It is true. you are right. I got confused because in debugger if you watch the variable then the records came, but only because I watched that.. This solution will solve my problem. thankyou

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.