这是我的代码:
public class RouteSingleton
{
private IDictionary<string, string> _dealCatLinks;
private IDictionary<string, string> _sectionLinks;
private IDictionary<string, string> _categoryLinks;
private IDictionary<string, string> _materials;
private IDictionary<string, string> _vendors;
public RouteSingleton(IDealService dealService
, ICategoryService categoryService
, IVendorService vendorService)
{
this._dealCatLinks = dealService.GetDealCatLinks("PLV").Distinct().ToDictionary(x => x, x => x);
this._sectionLinks = categoryService.GetSectionLinks("PLV").Distinct().ToDictionary(x => x, x => x);
this._categoryLinks = categoryService.GetMainCategoryLinks("PLV")
.Where(x => !_sectionLinks.ContainsKey(x)).Distinct().ToDictionary(x => x, x => x);
this._vendors = _vendorService.GetVendorLinks("PFB").Distinct().ToDictionary(x => x, x => x);
}
public bool IsDealCategory(string slug)
{
return _dealCatLinks.ContainsKey(slug);
}
public …Run Code Online (Sandbox Code Playgroud) 我想知道如何使用 mongo 驱动程序构建复杂的查询。这是我的查询:
var builder = Builders<MongoNavFilter>.Filter;
var query = builder.Where(x => x.Link == link && x.SubLink == subLink);
if (some statement)
{
var finalExpression = ...
query = query & Builders<MongoNavFilter>.Filter.Where(finalExpression);
}
if (onsale)
query = query & Builders<MongoNavFilter>.Filter.Where(x => !(x.Promo == null && x.Promo == string.Empty));
var filters = _db.GetCollection<MongoNavFilter>("NavFilters").
Find(query).ToList();
Run Code Online (Sandbox Code Playgroud)
这段EF IQueryable代码工作正常,但我无法使用mongo driver. 谁能告诉我我做错了什么?