[CSHARP-3009] BsonExtraElement query Created: 11/Mar/20  Updated: 31/Mar/22

Status: Backlog
Project: C# Driver
Component/s: API
Affects Version/s: 2.10.2
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: zeng pu Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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

 

 

 

 

 


Generated at Wed Feb 07 21:44:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.