示例#1
0
 public void SelectVariable(SparqlVariable v)
 {
     if (SelectBuilder != null)
     {
         if (v != null && !SelectedVariables.Any(x => x.Name == v.Name))
         {
             SelectedVariables.Add(v);
         }
     }
     else
     {
         string msg = "Cannot select variables with non-SELECT query type.";
         throw new Exception(msg);
     }
 }
示例#2
0
        public override void OnSelectClauseVisited(Expression selector)
        {
            base.OnSelectClauseVisited(selector);

            // If we are in the root query generator and have not yet selected the
            // subject variable, set it from the given selector.
            if (IsRoot && !SelectedVariables.Any())
            {
                SparqlVariable o = VariableGenerator.TryGetObjectVariable(selector);

                if (o != null && !IsSelectedVariable(o))
                {
                    SelectVariable(o);
                }
            }
        }
示例#3
0
        public void BindSelectVariables()
        {
            IsBound = true;

            if (SelectBuilder != null)
            {
                bool hasAggregate = SelectedVariables.Any(v => v.IsAggregate);

                foreach (SparqlVariable v in SelectedVariables)
                {
                    if (CoalescedVariables.ContainsKey(v))
                    {
                        SparqlExpression defaultValue = CoalescedVariables[v];

                        SelectBuilder.And(e => e.Coalesce(e.Variable(v.Name), defaultValue)).As(v.Name + '_');
                    }
                    else
                    {
                        SelectBuilder.And(v);
                    }

                    if (hasAggregate && !v.IsAggregate)
                    {
#if !NET35
                        SelectBuilder.GroupBy(v.Name);
#else
                        QueryBuilder.GroupBy(v.Name);
#endif
                    }
                }

                if (hasAggregate && !IsRoot)
                {
#if !NET35
                    SelectBuilder.Distinct();
#else
                    QueryBuilder.Distinct();
#endif
                }
            }
        }