コード例 #1
0
ファイル: Query.cs プロジェクト: shantiw/Entitybase
        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);
        }
コード例 #2
0
        // for $expand
        public void UnionFieldProperties(IEnumerable <string> fieldProperties)
        {
            foreach (string property in fieldProperties)
            {
                if (_query.Properties.Any(p => p.Name == property))
                {
                    continue;
                }

                Property oProperty = FieldProperty.Create(property, _query.Entity, _query.Schema);
                _properties.Add(oProperty);
            }
        }