MemberInit projection alias is mis-resolved as an EF property of the root entity

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Declined
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • 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

      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:
            Unassigned
            Reporter:
            Damien Guard
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: