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

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

    • Type: Icon: Improvement Improvement
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Feature Request
    • None

      For example,

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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?

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

              Created:
              Updated:
              Resolved: