Пример #1
0
        public QueryField GetOrCreateQueryField(ColumnReferenceExpression columnReference,
                                                bool isRepresentation, SelectPart selectPart)
        {
            var queryRoot = queryEntityRegistry.Get(columnReference.Table);

            if (!isRepresentation && selectPart == SelectPart.GroupBy)
            {
                QueryField fieldWithFunction;
                var        keyWithFunction = columnReference.Name + "." + true;
                if (queryRoot.fields.TryGetValue(keyWithFunction, out fieldWithFunction))
                {
                    if (fieldWithFunction.parts.Contains(SelectPart.Select))
                    {
                        isRepresentation = true;
                    }
                }
            }
            var        key = columnReference.Name + "." + isRepresentation;
            QueryField field;

            if (!queryRoot.fields.TryGetValue(key, out field))
            {
                var propertyNames    = columnReference.Name.Split('.');
                var subqueryRequired = propertyNames.Length > 1;
                var needInvert       = false;
                if (propertyNames[propertyNames.Length - 1].EqualsIgnoringCase("ЭтоГруппа"))
                {
                    needInvert       = true;
                    subqueryRequired = true;
                }
                var propertiesEnumerator = new PropertiesEnumerator(propertyNames, queryRoot, this);
                var referencedProperties = propertiesEnumerator.Enumerate();
                if (isRepresentation)
                {
                    if (ReplaceWithRepresentation(referencedProperties))
                    {
                        subqueryRequired = true;
                    }
                }
                string fieldAlias = null;
                if (subqueryRequired)
                {
                    queryRoot.subqueryRequired = true;
                    fieldAlias = nameGenerator.GenerateColumnName();
                }
                foreach (var p in referencedProperties)
                {
                    p.referenced = true;
                }
                field = new QueryField(fieldAlias, referencedProperties.ToArray(), needInvert);
                queryRoot.fields.Add(key, field);
            }
            if (!field.parts.Contains(selectPart))
            {
                field.parts.Add(selectPart);
            }
            return(field);
        }
Пример #2
0
        public List <QueryEntityProperty> GetProperties(QueryRoot queryRoot, string[] propertyNames)
        {
            var enumerator = new PropertiesEnumerator(propertyNames, queryRoot, this);

            return(enumerator.Enumerate());
        }