private BsonDocument[] Translate <T>(IQueryable <T> queryable) { var provider = (MongoQueryProvider <T>)queryable.Provider; var executableQuery = ExpressionToExecutableQueryTranslator.Translate <T, T>(provider, queryable.Expression); return(executableQuery.Pipeline.Stages.Select(s => (BsonDocument)s.Render()).ToArray()); }
private BsonDocument[] Translate <T>(IQueryable <T> queryable) { var queryProvider = (MongoQueryProvider <Person>)queryable.Provider; var executableQuery = ExpressionToExecutableQueryTranslator.Translate <Person, IGrouping <int, Person> >(queryProvider, queryable.Expression); return(executableQuery.Pipeline.Render().AsBsonArray.Cast <BsonDocument>().ToArray()); }
protected List <BsonDocument> Translate <TDocument, TResult>(IQueryable <TResult> queryable) { var provider = (MongoQueryProvider <TDocument>)queryable.Provider; var executableQuery = ExpressionToExecutableQueryTranslator.Translate <TDocument, TResult>(provider, queryable.Expression); var stages = executableQuery.Pipeline.Stages; return(stages.Select(s => s.Render().AsBsonDocument).ToList()); }
public void SelectMany_should_translate_correctly() { var client = DriverTestConfiguration.Linq3Client; var database = client.GetDatabase("test"); var collection = database.GetCollection <Item>("test"); var queryable = collection.AsQueryable() .SelectMany( x => x.Meta, (item, meta) => new ProjectedItem { ItemId = item.Id.ToString(), Meta = meta, Property = item.Properties.First(p => p.Id == meta.PropertyId) }); var provider = (MongoQueryProvider <Item>)queryable.Provider; var executableQuery = ExpressionToExecutableQueryTranslator.Translate <Item, ProjectedItem>(provider, queryable.Expression); var stages = executableQuery.Pipeline.Stages.Select(s => s.Render()); var expectedStages = new string[] { @" { $project : { _v : { $map : { input : '$Meta', as : 'meta', in : { ItemId : { $toString : '$_id' }, Meta : '$$meta', Property : { $arrayElemAt : [ { $filter : { input : '$Properties', as : 'p', cond : { $eq : ['$$p._id', '$$meta.PropertyId'] } } }, 0 ] } } } }, _id : 0 } }", @"{ $unwind : '$_v' }" }; stages.Should().Equal(expectedStages.Select(s => BsonDocument.Parse(s))); }