Rewrite binding for robustness with non-trivial shapes

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Unknown
    • 10.0.2, 9.1.2, 8.4.2
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Dotnet Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      For projections of the form Select(p => new SomeType { MemberA = <expr> }), MongoProjectionBindingExpressionVisitor.VisitMemberAssignment pushes the binding member name (MemberA) onto the projection-member stack. When ApplyProjection flattens the mapping, that name becomes the alias of the projection entry — even when the underlying expression has nothing to do with a property called MemberA.

        using var db = GuidesDbContext.Create(database.MongoDatabase);
        // Planet.name is a string EF property; p.orderFromSun is an int.
        // Alias becomes "name" (the binding member), the shaper resolves Planet.FindProperty("name"),
        // reads its nullability (true), and applies it to the int read.
        var results = db.Planets
            .Select(p => new Planet { name = p.orderFromSun.ToString() })
            .ToList(); 

      Which throws System.ArgumentException : Method 'System.String ToString()' declared on type 'System.Int32' cannot be called with instance of type 'System.Nullable`1[System.Int32]'

            Assignee:
            Damien Guard
            Reporter:
            Damien Guard
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: