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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sandeep Singh ShekhawatPosted Dec 5, 2012, 9:26 PM
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
VulpesPosted Dec 5, 2012, 9:02 AM
Posted Dec 5, 2012, 8:44 AM
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