-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.10.2
-
Component/s: API
-
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