public void ExpandWildcards(NPathSelectQuery query)
        {
            ArrayList newSelectFieldList = new ArrayList();
            foreach (NPathSelectField field in query.Select.SelectFields)
            {
                string fieldName = field.Alias;
                NPathIdentifier path = field.Expression as NPathIdentifier;
                if (path != null && path.IsWildcard)
                {
                    string[] parts = path.Path.Split('.');
                    NPathClassName className = (NPathClassName) query.From.Classes[0];

                    IClassMap classMap = Context.DomainMap.MustGetClassMap(className.Name);

                    int i = 0;
                    foreach (string part in parts)
                    {
                        if (i == parts.Length - 1)
                            break;

                        IPropertyMap property = classMap.MustGetPropertyMap(part);
                        classMap = Context.DomainMap.MustGetClassMap(property.DataType);
                        i++;
                    }

                    ArrayList properties = classMap.GetAllPropertyMaps();

                    foreach (PropertyMap property in properties)
                    {
                        if (property.ReferenceType != ReferenceType.None)
                            continue;

                        NPathSelectField newField = new NPathSelectField();
                        newField.Alias = null;
                        NPathIdentifier newPath = new NPathIdentifier();
                        if (parts.Length > 1)
                            newPath.Path = string.Join(".", parts, 0, parts.Length - 1) + ".";

                        newPath.Path += property.Name;
                        newField.Expression = newPath;
                        newSelectFieldList.Add(newField);
                    }
                }
                else
                {
                    newSelectFieldList.Add(field);
                }
            }
            query.Select.SelectFields = newSelectFieldList;
        }
Ejemplo n.º 2
0
        private void ParseSelectClause(NPathSelectClause selectClause)
        {
            if (tokenizer.GetNextToken().IsType("distinct"))
            {
                selectClause.Distinct = true;
                tokenizer.MoveNext();
            }

            if (tokenizer.GetNextToken().IsType("top"))
            {
                selectClause.HasTop = true;
                tokenizer.MoveNext();
                double top = double.Parse(tokenizer.GetNextToken("decimal", "Decimal value").Text); // do not localize
                selectClause.Top = (int) top;
                tokenizer.MoveNext();

                if (tokenizer.GetNextToken().IsType("percent"))
                {
                    selectClause.Percent = true;
                    tokenizer.MoveNext();
                }
                if (tokenizer.GetNextToken().IsType("with ties")) // do not localize
                {
                    selectClause.WithTies = true;
                    tokenizer.MoveNext();
                }
            }

            do
            {
                tokenizer.MoveNext();
                {
                    IValue expression = ParseExpression();
                    NPathSelectField field = new NPathSelectField();
                    field.Expression = expression;
                    field.Alias = null;
                    selectClause.SelectFields.Add(field);

                }

                if (tokenizer.GetCurrentToken().IsType("as"))
                {
                    NPathSelectField field = selectClause.SelectFields[selectClause.SelectFields.Count - 1] as NPathSelectField;
                    tokenizer.MoveNext();
                    field.Alias = tokenizer.GetCurrentToken().Text;
                    tokenizer.MoveNext();
                }

            } while (tokenizer.GetCurrentToken().IsType("comma"));
        }