2010-06-04 44 views
5

如何在实体框架中实现以下SQL查询。 SELECT * FROM Users WHERE UserID in (1,2,3,4)如何在实体框架4.0中实现SQL“in”

我试图做

var users = from e in context.Users where e.UserId in (list of user ids) 

感谢 Ashwani

+0

可能重复[LINQ到实体 - SQL “IN” 的条款( http://stackoverflow.com/questions/857973/linq-to-entities-sql-in-clause) – 2014-03-24 08:20:22

回答

8
var users = from e in context.Users where idList.Contains(e.UserId) 
9

试试这个:

var identifiers = new[] { 1, 2, 3, 4 }; 
var users = from e in context.Users where identifiers.Contains(e.UserId);