SQL In clause in LINQ (In LINQ operation like SQL In clause)

Hello Frd's


There are most of situation arise when we required to used IN clause of sql in our LINQ technology.

But LINQ not directly provide IN clause.We have to manage it another way.Below are simple example which do same thing.(SQL IN Clause in LINQ Technology)

  public static string[] GetOpenStatusIDListForInQueryLinq()  
     {  
       using (ITILDataContext context = new ITILDataContext(Common.ConnectionString))  
       {  
         //operation which return list of all id as string array  
       }  
     }  
 // below method perform Count Operation using IN query in LINQ  
 public static int Perfrominoperation()  
     {  
       using (ITILDataContext context = new ITILDataContext(Common.ConnectionString))  
       {  
         var incidentobj = from incident in context.AllIncidents  
                  where GetOpenStatusIDListForInQueryLinq().Contains(incident.StatusID.ToString())  
                 select incident;  
         return incidentobj.Count();  
       }  
     }  
 //Above function return all Records which have a iD resides in a String array and same id  
 resides in a Tabke of AllIncidents  



If you have any question or any suggestion please write in comment.

Enjoy !!!!!!!

Posted in | 3 comments