private static List <TProjection> Find <T, TProjection>(string collectionName, FilterDefinition <T> filter, SortDefinition <T> sort = null, ProjectionDefinition <T, TProjection> projection = null, int?pageNumber = 0, int?pageSize = 100, FindOptions findOptions = null, bool includeSchema = false) where TProjection : new() { var serializer = BsonSerializer.SerializerRegistry.GetSerializer <T>(); var projectionInfo = projection.Render(serializer, BsonSerializer.SerializerRegistry); var projectionAsJson = string.Empty; if (projectionInfo.Document != null) { projectionAsJson = projectionInfo.Document.ToJson(); } var request = new Find { CollectionName = collectionName, Filter = filter.ToJson(), Projection = projectionAsJson, Sort = sort.ToJson(), FindOptions = findOptions, PageSize = pageSize ?? 100, PageNumber = pageNumber ?? 0, IncludeSchema = includeSchema, OutputMode = JsonOutputMode.Strict, CultureCode = CultureInfo.CurrentCulture.Name }; var response = Send <FindResponse>("entities/" + collectionName + "/find", request, "POST"); if (response != null && response.Result.Any()) { var list = BsonSerializer.Deserialize <List <TProjection> >(response.Result); return(list); } return(new List <TProjection>()); }
public static List <T> Find <T>(string collectionName, FilterDefinition <T> filter, SortDefinition <T> sort = null, ProjectionDefinition <T> projection = null, int?pageNumber = 0, int?pageSize = 100, FindOptions findOptions = null, bool includeSchema = false) { var request = new Find { CollectionName = collectionName, Filter = filter.ToJson(), Projection = projection.ToJson(), Sort = sort.ToJson(), FindOptions = findOptions, PageSize = pageSize ?? 100, PageNumber = pageNumber ?? 0, IncludeSchema = includeSchema, OutputMode = JsonOutputMode.Strict, CultureCode = CultureInfo.CurrentCulture.Name }; var response = Send <FindResponse>("entities/" + collectionName + "/find", request, "POST"); if (response != null && response.Result.Any()) { var list = BsonSerializer.Deserialize <List <T> >(response.Result); return(list); } return(new List <T>()); }