Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-63

LINQ Support for All() subquery

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      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; }

      Attachments

        Activity

          People

            craig.wilson@mongodb.com Craig Wilson
            oliverw Oliver Weichhold
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: