Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Query DbContext with Linq conditions and async

so I have a line of code as such:

Portfolio portfolio = await _dbContext.Portfolios.FindAsync(id);

But I only want portfolios that have their IsDeleted value set to false.

And I need it to be async, so something like this :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Portfolio portfolio = await _dbContext.Portfolios.FindAsync(id).Where(p => p.IsDeleted == false);

Is this possible at all?

>Solution :

Is it this, what you are looking for.

Portfolio portfolio = await _dbContext.Portfolios.FirstOrDefaultAsync(p => p.Id &&  IsDeleted == false);

If you are looking for list of portfolio that you will do it like this

List<Portfolio> portfolios = await _dbContext.Portfolios.Where(p => p.Id &&  IsDeleted == false).ToList();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading