Querying Data with Ickle and the .NET Client
|
Tip
|
The source code for this tutorial is available on GitHub. |
This tutorial demonstrates how to register Protobuf schemas and run Ickle queries with the .NET Hot Rod client.
Prerequisites
-
A running Infinispan server.
-
.NET 10 or later.
Running the Example
dotnet run --project query
Code Walkthrough
Schema and Code Generation
The example uses a Protos/person.proto file with Grpc.Tools to generate a C# Person class at build time.
The same schema — with Infinispan indexing annotations — is registered on the server.
/* @Indexed */
message Person {
/* @Keyword(projectable = true, sortable = true, normalizer = "lowercase") */
string firstName = 1;
/* @Keyword(projectable = true, sortable = true, normalizer = "lowercase") */
string lastName = 2;
/* @Basic(projectable = true, sortable = true) */
int32 bornYear = 3;
/* @Keyword(projectable = true, sortable = true, normalizer = "lowercase") */
string bornIn = 4;
}
Creating a Typed Cache
The builder infers marshallers from the Person type and the Protobuf encoding.
No manual marshaller setup needed.
var cache = client.NewCache<Person>("indexedPeopleCache")
.WithEncoding(MediaType.Protobuf)
.Build();
Query All (Typed)
var allResults = await cache.Query<Person>("from tutorial.Person");
Query with Named Parameters
var results = await cache.Query<Person>("from tutorial.Person p where p.lastName = :lastName",
new Dictionary<string, object> { ["lastName"] = "Granger" });
Query with Projections
var results = await cache.Query("select p.firstName, p.lastName from tutorial.Person p where p.bornIn = 'London'");
foreach (object[] row in results)
Console.WriteLine($" {row[0]} {row[1]}");
Expected Output
Registered person.proto schema.
Cache 'indexedPeopleCache' ready.
Added 4 people.
=== Query all ===
Total results: 4
Hermione Granger
Harry Potter
Ron Wesley
Draco Malfoy
=== Query: people with lastName = 'Granger' ===
Hermione Granger
=== Query: projection of people born in London ===
Hermione Granger
Ron Wesley
Draco Malfoy
Cache removed.


