skip to Main Content

I have a request that takes in a list of ids and I want to return objects if they are found within that list

for example

public async Task<IEnumerable<ChatThread>> GetThreadByIDS(List<long> ids)
{
     // how do I query dbContext to get all chat threads based on a list of ids ?
}

2

Answers


  1. Something like this:

    public async Task<List<ChatThread>> GetThreadByIDS(List<long> ids)
    {
         var result = await this.dbContext.ChatThread.Where(x => ids.Contains(x.Id)).ToListAsync();
    
         return result;
    }
    
    Login or Signup to reply.
  2. Assuming that you have a list named "listOfIds" and your entity is "students".
    so your query should be :
    dbContext.Set().Where(x => listOfIds.Contains(x.Id));

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search