I'm trying to make a keys-only query to Google Cloud Datastore using a VB.net program. Google provides the C# code but I'm having trouble converting it to VB.
C# example code from Google:
Query query = new Query("Task")
{
Projection = { "__key__" }
};
My attempt at writing this in VB:
Dim db As DatastoreDb = DatastoreDb.Create("myProjectID")
Dim query As New Query("myKind")
query.Projection = "__key__"
Dim result as DatastoreQueryResults = db.RunQuery(query)
However, I get the error: Property 'Projection' is Read-Only.
I have gotten upserts, inserts, and deletes to work from my code, but this one is stumping me. How do I edit the Projection property to return only keys?
Although the property is read-only, it returns a collection which is mutable. The C# example you showed uses a nested collection initializer to populate the collection. The equivalent code in VB could call Add
:
Dim query As New Query("myKind")
query.Projection.Add("__key__")
(I don't know if there's appropriate object/collection initializer syntax in VB to make that briefer.)