Exemple #1
0
 private void PrepareQueryAttributes(SqlQuery query)
 {
     foreach (var field in _fields)
     {
         if (field.AttributeId != Guid.Empty)
         {
             var attr = query.FindAttribute(field.AttributeId);
             if (attr != null)
             {
                 query.AddAttribute(field.AttributeId);
             }
         }
         else
         {
             var attr = query.FindAttribute(field.AttributeName);
             if (attr != null)
             {
                 query.AddAttribute(field.AttributeName);
             }
         }
     }
 }
        public static SqlQueryAttribute BuildAttribute(SqlQuery query, QueryAttributeDef attrDef)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            if (attrDef == null)
            {
                throw new ArgumentNullException("attrDef");
            }

            var single = attrDef as QuerySingleAttributeDef;

            if (single != null)
            {
                var source = query.FindSource(single.Attribute.Source);

                return(single.Attribute.AttributeId != Guid.Empty
                    ? query.GetAttribute(source, single.Attribute.AttributeId)
                    : query.GetAttribute(source, single.Attribute.AttributeName));
            }
            var exp = attrDef as QueryExpAttributeDef;

            if (exp != null)
            {
                var attrRefs = new List <SqlQuerySourceAttributeRef>();

                foreach (var attribute in exp.Attributes)
                {
                    var source = query.FindSource(attribute.Source);

                    var attr = attribute.AttributeId != Guid.Empty
                        ? source.GetAttribute(attribute.AttributeId)
                        : source.GetAttribute(attribute.AttributeName);
                    var attrRef = new SqlQuerySourceAttributeRef(source, attr);
                    attrRefs.Add(attrRef);
                }
                return(query.AddAttribute(attrRefs, exp.Expression));
            }
            return(null);
        }