Entity Framework Core equivalent of SQL's "IN"

entity-framework-core sql

Question

In EF Core 1.1, I can get all users which have a certain ClientId:

var users = _context.Users.Where(u => u.ClientId == 1)

But is it possible to return all users that have a ClientId that fall in a set? Something like

var users = _context.Users.Where(u => u.ClientId IN (1, 2, 3, 4, 5))

?

1
3
8/2/2017 12:13:06 PM

Accepted Answer

I'm sure this hasn't changed from EF not-core:

var posValues = new [] { 1, 2, 3, 4, 5 };
var qry = _context.Users.Where(u => posValues.Contains(u.ClientId));

(And if you look at the generated SQL you'll see this translated into an IN expression.)

8
8/2/2017 12:14:49 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow