Esempio n. 1
0
        public Query(string entity, string select, string filter, string orderby, XElement schema, ParameterCollection parameters)
        {
            Entity     = entity;
            Schema     = new XElement(schema);
            Parameters = parameters;

            //
            Select = new Select(string.IsNullOrWhiteSpace(select) ? "*" : select, Entity, Schema);
            List <string>        parameterList = new List <string>();
            IEnumerable <string> properties    = Select.Properties;

            if (!string.IsNullOrWhiteSpace(filter))
            {
                Filter     = new Filter(filter, Entity, Schema);
                properties = properties.Union(Filter.Properties);
                parameterList.AddRange(Filter.Parameters);
            }
            if (!string.IsNullOrWhiteSpace(orderby))
            {
                Orderby    = new Orderby(orderby, Entity, Schema);
                properties = properties.Union(Orderby.Orders.Select(o => o.Property));
            }

            //
            List <Property> propertyList = new List <Property>();
            XElement        entitySchema = Schema.GetEntitySchema(Entity);

            foreach (string property in properties)
            {
                Property oProperty;

                XElement propertySchema = entitySchema.Elements(SchemaVocab.Property).FirstOrDefault(x => x.Attribute(SchemaVocab.Name).Value == property);
                if (propertySchema == null)
                {
                    if (!property.Contains("."))
                    {
                        throw new SyntaxErrorException(string.Format(ErrorMessages.NotFoundProperty, property, Entity));
                    }

                    oProperty = ExtendProperty.GenerateExtendProperty(property, Entity, schema);
                }
                else
                {
                    oProperty = FieldProperty.Create(property, entity, Schema);
                }

                propertyList.Add(oProperty);
            }

            Properties = new PropertyCollection(propertyList, this);

            Parameters.UnionParameters(parameterList);
        }
Esempio n. 2
0
        protected string GenerateOrderBy(Orderby orderby, Table table)
        {
            List <string> list = new List <string>();

            foreach (Order order in orderby.Orders)
            {
                Column column = table.Columns[order.Property];
                if (order is DescendingOrder)
                {
                    list.Add(string.Format("{0} {1}", ToSqlString(column, table), "DESC"));
                }
                else // AscendingOrder
                {
                    list.Add(string.Format("{0} {1}", ToSqlString(column, table), "ASC"));
                }
            }
            return("ORDER BY " + string.Join(",", list));
        }