Esempio n. 1
0
        T IQueryExecutor.ExecuteSingle <T>(QueryModel queryModel, bool returnDefaultWhenEmpty)
        {
            var isFirst = queryModel.ResultOperators.OfType <FirstResultOperator>().Any();

            // TODO -- optimize by using Top 1
            var cmd = BuildCommand <T>(queryModel);
            var all = _runner.QueryJson(cmd).ToArray();

            if (returnDefaultWhenEmpty && all.Length == 0)
            {
                return(default(T));
            }

            var data = isFirst ? all.First() : all.Single();

            return(_serializer.FromJson <T>(data));
        }