Ejemplo n.º 1
0
        public static string ToSql <TEntity>(this IQueryable <TEntity> queryable)
            where TEntity : class
        {
            if (!(queryable is EntityQueryable <TEntity>) && !(queryable is InternalDbSet <TEntity>))
            {
                throw new ArgumentException();
            }

            IQueryCompiler       queryCompiler       = (IQueryCompiler)_queryCompilerField.GetValue(queryable.Provider);
            IQueryModelGenerator queryModelGenerator = (IQueryModelGenerator)_queryModelGeneratorField.GetValue(queryCompiler);
            QueryModel           queryModel          = queryModelGenerator.ParseQuery(queryable.Expression);
            object database = _databaseField.GetValue(queryCompiler);
            IQueryCompilationContextFactory queryCompilationContextFactory = ((DatabaseDependencies)_dependenciesProperty.GetValue(database)).QueryCompilationContextFactory;
            QueryCompilationContext         queryCompilationContext        = queryCompilationContextFactory.Create(false);
            RelationalQueryModelVisitor     modelVisitor = (RelationalQueryModelVisitor)queryCompilationContext.CreateQueryModelVisitor();

            modelVisitor.CreateQueryExecutor <TEntity>(queryModel);
            return(modelVisitor.Queries.Join(Environment.NewLine + Environment.NewLine));
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Translates a query model into a function that can be executed to get query results from the database.
 /// </summary>
 /// <typeparam name="TResult"> The type of results returned by the query. </typeparam>
 /// <param name="queryModel"> An object model representing the query to be executed. </param>
 /// <returns> A function that will execute the query. </returns>
 public virtual Func <QueryContext, IEnumerable <TResult> > CompileQuery <TResult>(QueryModel queryModel)
 => _queryCompilationContextFactory
 .Create(async: false)
 .CreateQueryModelVisitor()
 .CreateQueryExecutor <TResult>(Check.NotNull(queryModel, nameof(queryModel)));
Ejemplo n.º 3
0
 public static EntityQueryModelVisitor CreateVisitor(this Database self, IQueryCompilationContextFactory factory, QueryModel qm)
 {
     return(factory.Create(async: false).CreateQueryModelVisitor());
 }
Ejemplo n.º 4
0
 public static EntityQueryModelVisitor CreateVisitor(this Microsoft.EntityFrameworkCore.Storage.Database self, IQueryCompilationContextFactory factory, QueryModel qm)
 {
     return(factory.Create(async: false).CreateQueryModelVisitor());
 }