/// <summary>
        /// Executes the given <paramref name="queryModel"/> as a collection query, i.e. as a query returning objects of type <typeparamref name="T"/>.
        ///             The query does not end with a scalar result operator, but it can end with a single result operator, for example
        ///             <see cref="T:Remotion.Linq.Clauses.ResultOperators.SingleResultOperator"/> or <see cref="T:Remotion.Linq.Clauses.ResultOperators.FirstResultOperator"/>. In such a case, the returned enumerable must yield exactly
        ///             one object (or none if the last result operator allows empty result sets).
        /// </summary>
        /// <typeparam name="T">The type of the items returned by the query.</typeparam><param name="queryModel">The <see cref="T:Remotion.Linq.QueryModel"/> representing the query to be executed. Analyze this via an
        ///             <see cref="T:Remotion.Linq.IQueryModelVisitor"/>.</param>
        /// <returns>
        /// A scalar value of type <typeparamref name="T"/> that represents the query's result.
        /// </returns>
        public IEnumerable <T> ExecuteCollection <T>(QueryModel queryModel)
        {
            var sparqlQuery = SparqlGeneratorQueryModelVisitor.GenerateSparqlQuery(_context, queryModel);

            return(sparqlQuery.IsInstanceQuery
                       ? _context.ExecuteInstanceQuery <T>(sparqlQuery.InstanceUri, sparqlQuery.TypeUri)
                       : _context.ExecuteQuery <T>(sparqlQuery));
        }
 public static SparqlQueryContext GenerateSparqlQuery(EntityContext context, QueryModel queryModel)
 {
     var visitor = new SparqlGeneratorQueryModelVisitor(context);
     visitor.VisitQueryModel(queryModel);
     var resultType = queryModel.GetResultType();
     if (resultType.IsGenericType)
     {
         resultType = resultType.GetGenericArguments()[0];
     }
     var bindType = context.GetImplType(resultType);
     bool useDescribe = typeof (IEntityObject).IsAssignableFrom(bindType);
     return visitor.GetSparqlQuery(useDescribe);
 }
 public static SparqlLinqQueryContext GenerateSparqlLinqQuery(EntityContext context, QueryModel queryModel)
 {
     var visitor = new SparqlGeneratorQueryModelVisitor(context);
     visitor.VisitQueryModel(queryModel);
     var resultType = queryModel.GetResultType();
     if (resultType.IsGenericType)
     {
         resultType = resultType.GetGenericArguments()[0];
     }
     var bindType = context.GetImplType(resultType);
     bool useConstruct = typeof (IEntityObject).IsAssignableFrom(bindType);
     return visitor.GetSparqlQuery(useConstruct);
 }