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

Left Joins With Three or More Collection Not Working

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.19.2
    • Affects Version/s: None
    • Component/s: None
    • None
    • Not Needed
    • 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?

      Summary

      When trying to join 3 or more collection with left join in single query the driver gives "Operation is not valid due to the current state of the object" error.

      MongoDB Version: 5.0.3

      .NET Driver Version: 2.18.0
      Linq Provider: V3

      How to Reproduce

      1) Create a linq left join query having 3 or more collections

      2) Try to execute it.

                • Linq Query -----*

       

      var teamDetailsQuery = (from team in _DBContext.Teams.AsQueryable()
                              join teamAllianceMappingsList in DBContext.TeamAllianceMappings.AsQueryable() on team.TeamId equals teamAllianceMappingsList.TeamId into teamAllianceMappingsListTemp
                              from allinceMapping in teamAllianceMappingsListTemp.DefaultIfEmpty()
      
                              join organizationAdminsList in _DBContext.OrganizationAdmins.AsQueryable() on team.OrganizationId equals organizationAdminsList.OrganizationId into organizationAdminsListTemp
                              from organizationAdmin in organizationAdminsListTemp.DefaultIfEmpty()
      
                              join usersList in _AGLMongoDBContext.Users.AsQueryable() on organizationAdmin.UserId equals usersList.UserId into usersListTemp
                              from organizationUser in usersListTemp.DefaultIfEmpty()
      
                              select new
                              {
                                  TeamId = team.TeamId,
                                  TeamName = team.TeamName,
                                  OrganizationLogo = (organizationUser != null ? organizationUser.ProfileImage : team.OrganizationLogo),
                                  OrganizationName = team.OrganizationName,
                                  AllianceTeamId = allinceMapping.AllianceTeamId
                              }).AsQueryable();
      
      var teamDetails = teamDetailsQuery.FirstOrDefault(); 

       

       

                • Error -----*

       

      System.InvalidOperationException: Operation is not valid due to the current state of the object.
      at MongoDB.Driver.Linq.Linq3Implementation.Serializers.WrappedValueSerializer`1.TryGetMemberSerializationInfo(String memberName, BsonSerializationInfo& serializationInfo)
      at MongoDB.Driver.Linq.Linq3Implementation.Misc.DocumentSerializerHelper.HasFieldInfo(IBsonSerializer serializer, String memberName)
      at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MemberExpressionToAggregationExpressionTranslator.Translate(TranslationContext context, MemberExpression expression)
      at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MemberExpressionToAggregationExpressionTranslator.Translate(TranslationContext context, MemberExpression expression)
      at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MemberExpressionToAggregationExpressionTranslator.Translate(TranslationContext context, MemberExpression expression)
      at MongoDB.Driver.Linq.Linq3Implementation.Misc.LambdaExpressionExtensions.GetFieldPath(LambdaExpression fieldSelectorLambda, TranslationContext context, IBsonSerializer parameterSerializer)
      at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.GroupJoinMethodToPipelineTranslator.Translate(TranslationContext context, MethodCallExpression expression)
      at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.SelectManyMethodToPipelineTranslator.Translate(TranslationContext context, MethodCallExpression expression)
      at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.GroupJoinMethodToPipelineTranslator.Translate(TranslationContext context, MethodCallExpression expression)
      at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.SelectManyMethodToPipelineTranslator.Translate(TranslationContext context, MethodCallExpression expression)
      at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.ExpressionToExecutableQueryTranslator.Translate[TDocument,TOutput](MongoQueryProvider`1 provider, Expression expression)
      at MongoDB.Driver.Linq.Linq3Implementation.MongoQuery`2.ToString() 

       

       

                • Expression -----*
                  {agl.Teams.Aggregate([]).GroupJoin(agl.TeamAllianceMappings.Aggregate([]), team => team.TeamId, teamAllianceMappingsList => teamAllianceMappingsList.TeamId, (team, teamAllianceMappingsListTemp) => new <>f__AnonymousType307`2(team = team, teamAllianceMappingsListTemp = teamAllianceMappingsListTemp)).SelectMany(<>h__TransparentIdentifier0 => <>h__TransparentIdentifier0.teamAllianceMappingsListTemp.DefaultIfEmpty(), (<>h__TransparentIdentifier0, allinceMapping) => new <>f__AnonymousType308`2(<>h__TransparentIdentifier0 = <>h__TransparentIdentifier0, allinceMapping = allinceMapping)).GroupJoin(agl.OrganizationAdmins.Aggregate([]), <>h__TransparentIdentifier1 => <>h__TransparentIdentifier1.<>h__TransparentIdentifier0.team.OrganizationId, organizationAdminsList => Convert(organizationAdminsList.OrganizationId, Nullable`1), (<>h__TransparentIdentifier1, organizationAdminsListTemp) => new <>f__AnonymousType309`2(<>h__TransparentIdentifier1 = <>h__TransparentIdentifier1, organizationAdminsListTemp = organizationAdminsListTemp)).SelectMany(<>h__TransparentIdentifier2 => <>h__TransparentIdentifier2.organizationAdminsListTemp.DefaultIfEmpty(), (<>h__TransparentIdentifier2, organizationAdmin) => new <>f__AnonymousType310`2(<>h__TransparentIdentifier2 = <>h__TransparentIdentifier2, organizationAdmin = organizationAdmin)).GroupJoin(agl.Users.Aggregate([]), <>h__TransparentIdentifier3 => <>h__TransparentIdentifier3.organizationAdmin.UserId, usersList => usersList.UserId, (<>h__TransparentIdentifier3, usersListTemp) => new <>f__AnonymousType311`2(<>h__TransparentIdentifier3 = <>h__TransparentIdentifier3, usersListTemp = usersListTemp)).SelectMany(<>h__TransparentIdentifier4 => <>h__TransparentIdentifier4.usersListTemp.DefaultIfEmpty(), (<>h__TransparentIdentifier4, organizationUser) => new <>f__AnonymousType312`5(TeamId = <>h__TransparentIdentifier4.<>h__TransparentIdentifier3.<>h__TransparentIdentifier2.<>h__TransparentIdentifier1.<>h__TransparentIdentifier0.team.TeamId, TeamName = <>h__TransparentIdentifier4.<>h__TransparentIdentifier3.<>h__TransparentIdentifier2.<>h__TransparentIdentifier1.<>h__TransparentIdentifier0.team.TeamName, OrganizationLogo = IIF((organizationUser != null), organizationUser.ProfileImage, <>h__TransparentIdentifier4.<>h__TransparentIdentifier3.<>h__TransparentIdentifier2.<>h__TransparentIdentifier1.<>h__TransparentIdentifier0.team.OrganizationLogo), OrganizationName = <>h__TransparentIdentifier4.<>h__TransparentIdentifier3.<>h__TransparentIdentifier2.<>h__TransparentIdentifier1.<>h__TransparentIdentifier0.team.OrganizationName, AllianceTeamId = <>h__TransparentIdentifier4.<>h__TransparentIdentifier3.<>h__TransparentIdentifier2.<>h__TransparentIdentifier1.allinceMapping.AllianceTeamId))} 

                  Additional Background

       

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            uday.dangrecha@gmail.com Uday Dangrecha
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: