I got tried of typing:
var result = from s in source
where items.Contains(s)
select s;
and so I implemented the IN
and NOT IN
methods as extension methods:
public static IQueryable<T> In<T>(this IQueryable<T> source,
IQueryable<T> checkAgainst)
{
return from s in source
where checkAgainst.Contains(s)
select s;
}
public static IQueryable<T> NotIn<T>(this IQueryable<T> source,
IQueryable<T> checkAgainst)
{
return from s in source
where !checkAgainst.Contains(s)
select s;
}
Thus, I can now just do the following:
var result = source.In(items);
What do you think – Good idea, Bad idea, Useless idea?
Reddit
Nizar Noorani is an independent software consultant. He provides services in the areas of web applications and systems architecture, analysis, design and development. Although proficient in a variety of technologies, he specializes in the .NET technology. He can be reached at nizar.noorani@gmail.com.