public static OrQuery Select <T>(Expression <Func <T, object> > selector, bool distinct = false, string collectionName = null) { var schema = TypeDescriptionsCache.GetDescription(typeof(T)); collectionName ??= schema.CollectionName; // create a fake queryable to force query parsing and capture resolution var executor = new NullExecutor(schema, collectionName); var queryable = new NullQueryable <T>(executor); if (!distinct) { var unused = queryable.Select(selector).ToList(); } else { var unused = queryable.Select(selector).Distinct().ToList(); } var query = executor.Expression; query.CollectionName = typeof(T).Name; return(query); }
public static OrQuery OrderBy <T, R>(Expression <Func <T, R> > selector, bool descending = false, string collectionName = null) { var schema = TypeDescriptionsCache.GetDescription(typeof(T)); // create a fake queryable to force query parsing and capture resolution var executor = new NullExecutor(schema, collectionName ?? schema.CollectionName); var queryable = new NullQueryable <T>(executor); var unused = descending ? queryable.OrderByDescending(selector).ToList() : queryable.OrderBy(selector).ToList(); var query = executor.Expression; query.CollectionName = typeof(T).Name; return(query); }
public static OrQuery PredicateToQuery <T>(Expression <Func <T, bool> > where, string collectionName = null) { var schema = TypeDescriptionsCache.GetDescription(typeof(T)); collectionName ??= schema.CollectionName; // create a fake queryable to force query parsing and capture resolution var executor = new NullExecutor(schema, collectionName); var queryable = new NullQueryable <T>(executor); var unused = queryable.Where(where).ToList(); var query = executor.Expression; query.CollectionName = typeof(T).Name; return(query); }