Created
July 24, 2019 10:55
-
-
Save AKlaus/7d9a7e6ad135f3905d27a22c0752a3a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Raven.Client.Documents; | |
using Raven.Client.Documents.Linq; | |
using Raven.Client.Documents.Operations; | |
using Raven.Client.Documents.Queries; | |
using System; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace ConsoleApp2 | |
{ | |
class Program | |
{ | |
public class Person | |
{ | |
public string Id { get; set; } | |
public string Filter { get; set; } | |
} | |
static void Main() | |
{ | |
MainAsync().Wait(); | |
} | |
static async Task MainAsync() | |
{ | |
const int ceiling = 2_000; | |
using(var store = new DocumentStore | |
{ | |
Urls = new[] { "http://live-test.ravendb.net" }, | |
Database = "test" | |
}) | |
{ | |
store.Initialize(); | |
// Delete all documents | |
var operation = await store.Operations.SendAsync(new DeleteByQueryOperation( | |
new IndexQuery { Query = "from @all_docs as d" }, | |
new QueryOperationOptions | |
{ | |
RetrieveDetails = true | |
} | |
)); | |
await operation.WaitForCompletionAsync<BulkOperationResult>(); | |
using (var s = store.OpenSession()) | |
{ | |
for (var i = 1; i < ceiling; i++) | |
s.Store(new Person { Filter = i.ToString() }); | |
s.SaveChanges(); | |
} | |
var list = Enumerable.Range(1, ceiling).Select(x => x.ToString()).ToList(); | |
Console.WriteLine("Start query..."); | |
using (var s = store.OpenSession()) | |
{ | |
var q = from doc in s.Query<Person>() | |
where doc.Filter.In(list) | |
select doc; | |
var records = q.ToArray(); | |
} | |
Console.ReadKey(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment