Click here to Skip to main content
15,667,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Every,

As i am new in linq please help me to convert a sql query into linq. My query in as below.

Select * from TableName Where Field_Name In (1,2,8,4)

Thanks in Advance.
Gihan Liyanage 11-Sep-14 6:42am    
You can easily do it with

try this.
var result = from tbl in TableName
             where tbl.Field_name = 1 ||tbl.Field_name = 2
              || tbl.Field_name = || tbl.Field_name = 4;

if any issue then let me know
Share this answer
Rahul JR 11-Sep-14 8:06am    
or is not working...
MuhammadUSman1 12-Sep-14 0:16am    
Replace or with ||. it should work
try Once..

var result= from objTbl in objModel.TableName where new[] { 1, 2,8,4}.Contains(objTbl .Field_name ) select objTbl ;

String????then try this..

var result= from objTbl in objModel.TableName where new[] { "1","2","8","4"}.Contains(objTbl .Field_name ) select objTbl ;
Share this answer
SQL IN equivalent in LINQ is .Contains(). So create a collection of values and use .Contains() method like follows:

var lstItems = new List<int>(){1, 2,8,4};

var result= from item in Context.Table_Name where lstItems.Contains(item.Column_Name) select item;</int>

Hope it helps.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900