John John - 7 months ago 43
SQL Question

create query that uses IN returning wrong values

The query

select * from PositionTable where Position in (51000785,52012986)

returns two records where the position column is '51000785' in the first record and '52012986' in the second.

Using C# I want to return the same results..I have tried

string allPositions = "51000785,52012986";
List<PositionTable> Position = new List<PositionTable>();
Position = DbContext.PositionTableList
.Where<PositionTable>(p => p.Position == allPositions)

This result returns nothing, so how can I change the ==allPositions to 'in (allPositions)' is this possible?


Answer Source

Try something like this:-

        var allPositions = new string[] { "51000785", "52012986" };
        var x = from p in DbContext.PositionTableList
            where allPositions.Contains(p.Position)
            select p;                          
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download