0

I am new to .Net Framework and am no expert in any programming language. I am just learning new things.

I want to get a list of objects from my database with Ids of 2, 6, and 9 and also all objects with Ids greater than 20. Here is my code.

int [] toRemove= { 2, 6, 9 };
var contributions = dbContext.FoodMenu
    .Where(x => toRemove.Contains(x.Id))
    .ToList();

As you see, the query with all Ids that are greater than 20 is not yet included. Is there a way I can add to the list with a single query only? How can I do that? Thank you so much.

1 Answer 1

1

Add || or condition for Id is greater than 20.

The query will fetch either the Ids within (2, 6, 9) or greater than 20.

int [] toRemove= { 2, 6, 9 };
var contributions = dbContext.FoodMenu
    .Where(x => toRemove.Contains(x.Id)
        || x.Id > 20)
    .ToList();
Sign up to request clarification or add additional context in comments.

Comments

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.