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]'