I have the following SQL query. How can I create the same query in LINQ?
select * from table1 t1
join table2 t2
on t1.col1 = t2.col1
where t2.col2 in ('A','B','C' )
I have the following SQL query. How can I create the same query in LINQ?
select * from table1 t1
join table2 t2
on t1.col1 = t2.col1
where t2.col2 in ('A','B','C' )
You can use Contains
:
string[] stringCollection = { "A", "B", "C" };
var query = from t1 in db.Table1
join t2 in db.Table2
on t1.col1 equals t2.col1
where stringCollection.Contains(t2.col2)
select new { t1, t2 };
You can't query in LinQ - Crm with 'IN'.
What you can do is retrieve the records, after you have a List<Entityt>
you use LinQ or a foreach to filter the records you need.