$ match в настоящее время поддерживается только тогда, когда это первый и единственный этап конвейера агрегации - PullRequest
0 голосов
/ 30 мая 2018

У меня есть следующий код, который работает локально:

public async Task GetConnections(string enterpriseId, IEnumerable<PermittedCommunicationType> permittedCommunication)
{
    IQueryable<ConnectionGetDto> query;
    query = await Task.Run(() =>
                from conn in _connectionCollection.AsQueryable()
                where (conn.EnterpriseId == enterpriseId)
                join consumer in _consumerCollection.AsQueryable() on conn.ConsumerId equals consumer.Id into joined
                select new ConnectionGetDto
                {
                    Id = conn.Id,
                    AdditionalData = conn.AdditionalData,
                    FirstName = joined.First().Profile.FirstName,
                }
                into p
                select p);

    query = ApplyEnterpriseConnectionPermissionFilter(query, permittedCommunication);

    var totalRecords = query.Count(); // Error when using Cosmos DB
}

private IQueryable<ConnectionGetDto> ApplyFilter(IQueryable<ConnectionGetDto> query, IEnumerable<CommunicationType> communicationType)
{
    if (permittedCommunication != null)
    {
        foreach (var p in permittedCommunication)
        {
            switch (p)
            {
                case PermittedCommunicationType.Call:
                    query = query.Where(c => c.PermittedCommunication.Call);
                    break;
                case PermittedCommunicationType.Email:
                    query = query.Where(c => c.PermittedCommunication.Email);
                    break;
                case PermittedCommunicationType.Im:
                    query = query.Where(c => c.PermittedCommunication.Im);
                    break;
                case PermittedCommunicationType.Letter:
                    query = query.Where(c => c.PermittedCommunication.Letter);
                    break;
                case PermittedCommunicationType.Sms:
                    query = query.Where(c => c.PermittedCommunication.Sms);
                    break;
            }
        }
    }

    return query;
}

Однако - при развертывании его в Cosmos DB, в этой строке:

var totalRecords = query.Count();

я получаю следующую ошибку:

{
  "_t": "OKMongoResponse",
  "ok": 0,
  "code": 118,
  "errmsg": "$match is currently only supported when it is the first and only stage of the aggregation pipeline. Please restructure your query to combine multiple $match stages into a single $match stage.",
  "$err": "$match is currently only supported when it is the first and only stage of the aggregation pipeline. Please restructure your query to combine multiple $match stages into a single $match stage."
}

Это, по-видимому, вызвано модификациями метода ApplyFilter в запросе.

Кто-нибудь знает, как я могу реструктурировать свой запрос, чтобы я мог добавить дополнительные аргументы после сборкиосновная часть моего запроса?

...