Blogger news

Blogger templates

Friday, June 24, 2011

LINQ IN clause(Sql server IN operator in LINQ)

Sql Server "IN" eqivalent can be implemented in LINQ query using "Contains" method. Find the sample code below.

string s = "b,a,c,d,e,f,g,h,i,j,k,l,m";
string[] strsplt = s.Split(',');
List abc = new List() { "a", "k", "b", "g", "z", "i" };
List final = new List();
strsplt.ToList().ForEach(a =>

{

final.Add(abc.Where(b => b.Contains(a)).FirstOrDefault());

final = final.Where(kc => kc != null).ToList();

}

);

No comments:

Post a Comment