|
It would nice if the LINQ Provider would offer support for List<T>.TrueForAll(), Enumerable.All() or both so that something like the sample below would work out of the box:
class Post
{
string Title;
string Body;
List<string> Tags;
}
This SearchByTag is supposed to search for all Posts containing ALL the tags.
public List<Snip> SearchByTag(List<string> Tags, int PageSize, int
StartPage, int PageCount)
{
using (var db = ServiceLocator.Get<IMongo>())
{
var posts = db.GetCollection<Post>();
List<Post> result;
int skip = StartPage*PageSize;
int take = PageCount*PageSize;
if (Tags != null && Tags.Count > 0)
result = posts.AsQueryable().Where(x => Tags.All(x.Tags.Contains)).OrderByDescending(x =>
x.LastAccess).Skip(skip).Take(take).ToList();
else
result = posts.AsQueryable().OrderByDescending(x => x.LastAccess).Skip(skip).Take(take).ToList();
return result;
}
|