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

BsonExtraElement query

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.10.2
    • Component/s: API
    • Labels:
      None

      for this scene

      Here is my model class:

      {{}}

      public class MongoProductEntity 
      {
          public MongoProductEntity()
          {
              AdditionalColumns = new BsonDocument { AllowDuplicateNames = false };
          }
          [BsonExtraElements]
          public BsonDocument AdditionalColumns { get; set; }
          public string BrandName { get; set; }
      }
      

      {{}}{{}}Here is the query part:

       var productEntity = new MongoProductEntity ()
              {
                  BrandName = "Brand"
              };            
              productEntity.AdditionalColumns.Add("testProperty", 6);
              productEntity.AdditionalColumns.Add("testProperty2", "almafa");
      
              await productEntityRepo.InsertAsync(productEntity);
              var qq = productEntityRepo.Where(x => x.AdditionalColumns["testProperty"] == 6).ToList();
      

      a solution is like this

      var filter = Builders<BsonDocument>.Filter.Eq("testProperty2", "almafa");
      productEntityRepo.Where((dbModel) => dbModel.BrandName == "Brand" && filter.Inject());
      

      but this is not friendly

      MongoDb.Driver has many ExpressionVistor,the query like 

      productEntityRepo.Where(x => x.AdditionalColumns["testProperty"] == 6
      

      can be convert to 

      var filter = Builders<BsonDocument>.Filter.Eq("testProperty2", "almafa"); productEntityRepo.Where((dbModel) => dbModel.BrandName == "Brand" && filter.Inject());
      

      in driver internal, this is more important for general queries,to avoid using the above code,that more friendly

       

       

       

       

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            zengpu2109@126.com zeng pu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: