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

exclude an member/field when use Expression to create Projection Definition

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Works as Designed
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • Feature Request
    • None

    Description

      For example,

      class Widget
      {
          [BsonElement("x")]
          public int X { get; set; }
       
          [BsonElement("y")]
          public int Y { get; set; }
       
          [BsonElement("name")]
          public string Name { get; set; }
      }
      

      We can create the ProjectionDefinition like this:

      var projection = Builders<Widget>.Projection<Widget>.Expression(x => new { X = x.X, Y = x.Y });
      
      

      How about we want to use the expression to exclude a memeber/field?

      Can we support something like this:

      var projection = Builders<Widget>.Projection<Widget>.Expression(x => new { Name = null });
      

      Basically in the expression, if the right-hand operand is default(T), we treat it as excluded field/member.

      Is that possible?

      Attachments

        Activity

          People

            robert@mongodb.com Robert Stam
            liuhongbo Hongbo Liu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: