Search code examples
c#searchhashset

C# Grabbing subset of table based off a Hashset if Ints


I have an Order and OrderMaster table. First I query the Master table, I then create a hashset of a column of Ints from that table. Lastly I want to get all orders that have those values.

When I do the contains, the ToList() fails and I get an error

Type bool does not contain member ToList

What am I doing wrong here?

mappings = await _context.OrderMapping
                         .Where((OrderMapping em) => em.MOID == UID)
                         .ToListAsync();

HashSet<int> ids2 = new HashSet<int>((mappings.Select(a => a.ORDERMAPID)));

orders = await _context.Order
                       .Where(x => ids2.Contains(x.ORDERMAPID)
                       .ToListAsync();

Solution

  • Seems like you are missing a ")" after Contains(...). The following should work :)

    orders = await _context.Order.Where(x => ids2.Contains(x.ORDERMAPID)).ToListAsync();