public Expression <Func <TEntity, bool> > Compile <TEntity>(string query) where TEntity : class { if (!_configuration.Mappings.TryGetValue(typeof(TEntity), out var entityConfiguration)) { throw new InvalidOperationException("Entity has not been configured."); } // Parse the expression. var expression = QueryExpressionParser.Parse(entityConfiguration, query); // expression = CollectionRewriter.Rewrite(expression); expression = BooleanRewriter.Rewrite(expression); expression = ConversionRewriter.Rewrite(expression); // Translate the expression. return(QueryTranslator <TContext, TEntity> .Translate(expression)); }
public static string ToSql(QueryConfiguration <TContext> configuration, string query) { var entityType = typeof(TEntity); if (!configuration.Mappings.TryGetValue(typeof(TEntity), out var entityConfiguration)) { throw new InvalidOperationException("Entity has not been configured."); } // Parse the expression and rewrite it. var expression = ExpressionParser.Parse(query); expression = BooleanRewriter <TEntity> .Rewrite(expression); expression = NullRewriter <TEntity> .Rewrite(expression); // Generate the SQL statement. return(GenerateSqlStatement(entityConfiguration, expression)); }
public IQueryable <TEntity> Query <TEntity>(TContext context, string query) where TEntity : class { if (!_configuration.Mappings.TryGetValue(typeof(TEntity), out var entityConfiguration)) { throw new InvalidOperationException("Entity has not been configured."); } // Parse the expression. var expression = QueryExpressionParser.Parse(entityConfiguration, query); expression = BooleanRewriter.Rewrite(expression); expression = NullableRewriter.Rewrite(expression); // Translate the expression. var result = QueryTranslator <TContext, TEntity> .Translate(expression); return(entityConfiguration.IsQueryType ? context.Query <TEntity>().Where(result) : context.Set <TEntity>().Where(result)); }