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

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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Feature Request
    • Labels:
      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

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: