Linq join error when add .Where() to foreign collection queryable

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Critical - P2
    • None
    • Affects Version/s: 3.0.0
    • Component/s: LINQ, LINQ3
    • None
    • None
    • Dotnet Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Driver version: 3.0.0 (I've tried all versions between 2.20.0 to 3.0.0 and none of them worked)

      .NET SDK Version 8.0.403

      Trivial example:

      BsonClassMap.RegisterClassMap<Pages>(cm =>
      {
          cm.AutoMap();
          cm.MapIdMember(c => c.Id);
      });
      
      BsonClassMap.RegisterClassMap<PageContainer>(cm =>
      {
          cm.AutoMap();
          cm.MapIdMember(c => c.Id);
      });
      
      var client = new MongoClient("mongodb://localhost:27017");
      var database = client.GetDatabase("playground");
      
      var pages = database.GetCollection<Pages>("pages");
      var pageContainers = database.GetCollection<PageContainer>("pagecontainers");
      
      var pagesWithContainers = await (from page in pages.AsQueryable().Where(x => x.TenantId == 1)
          join container in pageContainers.AsQueryable() on page.Id equals container.PageId into containers
          select new
          {
              page.Id,
              page.Title,
              Containers = containers
          }).ToListAsync();  
      
      Console.ReadLine();
      
      public class Pages
      {
          public required ObjectId Id { get; init; }
          public required string Title { get; init; }
      }
      
      public class PageContainer
      {
          public required ObjectId Id { get; init; }
          public required ObjectId PageId { get; init; }
          public required string Content { get; init; }
      } 

      The exception i get:

       

      Unhandled exception. MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: playground.pagecontainers.Aggregate([]).Where(x => (x.TenantId == 1)) in playground.pages.Aggregate([]).Where(x => (x.TenantId == 1)).GroupJoin(playground.pagecontainers.Aggregate([]).Where(x => (x.TenantId == 1)), page => page.Id, container => container.PageId, (page, containers) => new <>f__AnonymousType0`3(Id = page.Id, Title = page.Title, Containers = containers)) because inner expression must be a MongoDB IQueryable against a collection.
         at MongoDB.Driver.Linq.Linq3Implementation.ExtensionMethods.ExpressionExtensions.GetCollectionInfo(Expression innerExpression, Expression containerExpression)
         at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.GroupJoinMethodToPipelineTranslator.Translate(TranslationContext context, MethodCallExpression expression)
         at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.ExpressionToPipelineTranslator.Translate(TranslationContext context, Expression expression)
         at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.ExpressionToExecutableQueryTranslator.Translate[TDocument,TOutput](MongoQueryProvider`1 provider, Expression expression, ExpressionTranslationOptions translationOptions)
         at MongoDB.Driver.Linq.Linq3Implementation.MongoQuery`2.ToCursorAsync(CancellationToken cancellationToken)
         at MongoDB.Driver.IAsyncCursorSourceExtensions.ToListAsync[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)
         at Program.<Main>$(String[] args) in /Users/keremacer/Projects/Playground/Playground/Program.cs:line 25
         at Program.<Main>(String[] args)
        

       

      If I remove ".Where(x => x.TenantId == 1)" from pageContainers.AsQueryable(), it works

              Assignee:
              Unassigned
              Reporter:
              kerem N/A
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated: