Get a List of Entities from a List of IDs in C#

I've always had to think to get this right the first time.

ebeeraheem

View Profile
15 views
Jun 21, 2025

If you have a list of categoryIds, you can retrieve the category entities for those IDs like so

var categories = await context.Categories
          .Where(c => categoryIds.Contains(c.Id))
          .ToListAsync();

Then you can compare the number of categories retrieved with the number of category IDs to validate them

Proceed as necessary.