Hi All,
How would I convert the SQL IN statement to LinQ
Select *
from TableName
where FieldName in (Value1, Value2)
or
Select *
from Table1
where Field1 in (Select Field1 from Table2)
Thanks
Jon Skeet [C# MVP] - 12 Mar 2008 18:04 GMT
> How would I convert the SQL IN statement to LinQ
>
[quoted text clipped - 7 lines]
> from Table1
> where Field1 in (Select Field1 from Table2)
Try the Contains() operator. I haven't tried it for the latter type of
subquery, but I've seen it work for the first type where you pass in
the values.
Just remember that it's the other way round, so:
set.Contains(value) ~= value in set

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Alberto Poblacion - 12 Mar 2008 22:11 GMT
> How would I convert the SQL IN statement to LinQ
>
[quoted text clipped - 7 lines]
> from Table1
> where Field1 in (Select Field1 from Table2)
As to the second one, it can be refactored into a Join:
Select Table1.* from Table1 Join Table2 on Table1.Field1=Table2.Field1
This can then be readily converted into a LINQ query with a Join.