Like
select * from tablename
where columnname in (1,2,3,4)
but in Linq Queue, What is the syntax of using IN keyword?
Thankyou
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Posted Dec 5, 2012, 3:44 AM EST
AdventureWorks.DB db=new DB();
var itemQuery = from cartItems in db.SalesOrderDetails
where cartItems.SalesOrderID == 75144
select cartItems.ProductID;
var myProducts = from p in db.Products
where itemQuery.Contains(p.ProductID)
select p;
http://msdn.microsoft.com/en-us/vstudio/bb688084.aspx
VulpesRank #55 · 29.2K reputationPosted Dec 5, 2012, 4:02 AM EST
Sandeep Singh ShekhawatRank #147 · 15.6K reputationPosted Dec 5, 2012, 4:26 PM EST
private void GetEmployee()
{
int[] Ids = { 1, 2, 3, 4 };
EmployeeOperationDataContext employeeContext = new EmployeeOperationDataContext();
var employee = from emp in employeeContext.EMPLOYEEs
where Ids.Contains(emp.Id)
select emp;
gridEmployee.DataSource = employee;
gridEmployee.DataBind();
}
Above query will be generated as below in debug mode to execute on sql server:
SELECT [t0].[Id], [t0].[Name], [t0].[SALARY]
FROM [dbo].[EMPLOYEE] AS [t0]
WHERE [t0].[Id] IN (@p0, @p1, @p2, @p3)
Hope It would be helpful.
Thanks
Sandeep