Esempio n. 1
0
        public SelectQueryBase(QueryBase innerQuery, LambdaExpression selector)
        {
            InnerQuery = innerQuery;
            Selector   = selector;
            Columns    = GetColumns(selector);

            var groupByQuery = GetGroupByQuery(innerQuery);

            if (groupByQuery != null)
            {
                // All group by keys must be present in the select statement
                var groupByNames = new HashSet <string>(groupByQuery.KeyColumns.Select(k => k.Property.Name));

                foreach (var expression in (selector.Body as NewExpression).Arguments)
                {
                    if (expression is MemberExpression keyProperty &&
                        keyProperty.Member is PropertyInfo &&
                        keyProperty.Expression is MemberExpression keysProperty &&
                        keysProperty.Member is PropertyInfo &&
                        keysProperty.Expression.NodeType == ExpressionType.Parameter &&
                        keysProperty.Member.Name == nameof(IGroupedRow <object, object> .Keys))
                    {
                        groupByNames.Remove(keyProperty.Member.Name);
                    }
                }

                if (groupByNames.Count > 0)
                {
                    throw QueryBuilderError.SelectGroupByKeyNotPresentInSelect().AsException();
                }
            }
        }
 public async void Error_On_All_GroupBy_Keys_Not_Present_In_Select_Statement(string location, string query)
 {
     await VerifySelectErrorRaised(QueryBuilderError.SelectGroupByKeyNotPresentInSelect(), query, location);
 }