Convert SQL to Linq where there is in clause

slamsal picture slamsal · Jun 28, 2012 · Viewed 8.5k times · Source

I would like to know how to convert SQL query listed below into LINQ query in VB.

SELECT FacilityID 
FROM tblFacilityProjects 
WHERE FreedomEnabled = True and ProjectID in (840,841,842)

Answer

mellamokb picture mellamokb · Jun 28, 2012

Something like this should do it I think:

Dim projectIds = New Integer() {840, 841, 842}
Dim result = From proj In db.tblFacilityProjects _
             Where proj.FreedomEnabled = True AndAlso _
                   projectIds.Contains(proj.ProjectID) _
             Select FacilityID