Пример #1
0
        public string GenerateAggregateQuery(Database.AggregateFunction function, string propertyName, string fromTables)
        {
            var sqlFunction = function.ToString();

            var columnValueExpression = PropertyMappings[propertyName];

            if (function == Database.AggregateFunction.Average)
            {
                sqlFunction = "AVG";

                if (typeof(T).GetProperty(propertyName).PropertyType.IsAnyOf(typeof(int), typeof(int?)))
                {
                    columnValueExpression = $"CAST({columnValueExpression} AS decimal)";
                }
            }

            return($"SELECT {sqlFunction}({columnValueExpression}) FROM {fromTables}" + GenerateWhere());
        }