Reference documentation and code samples for the Google.Cloud.Spanner.Data class KeySet.
Immutable class that defines a set of keys to select from a table or index.
KeySets are used for Read operations to specify the rows that should be returned
by the read. A KeySet can be created from a set of individual keys or a set of
key ranges. The All instance can be used for read operations
that should return all rows.
using var cmd = connection.CreateReadCommand(
"MyTable",
ReadOptions.FromColumns("MyCol1", "MyCol2"),
KeySet.FromKeys(new Key("k1"), new Key("k2")));
using var reader = await cmd.ExecuteReaderAsync();
Properties
All
public static KeySet All { get; }
Returns a key set that selects all keys in the table or index.
public string ToString(SpannerConnectionStringBuilder builder)
Returns the string representation of this KeySet using the type conversion options specified in
SpannerConnectionStringBuilder. The string representation is only for diagnostic purposes
and the implementation may change over time.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThe latest version of the \u003ccode\u003eKeySet\u003c/code\u003e class is \u003ccode\u003e5.0.0-beta05\u003c/code\u003e, with multiple previous versions available, down to version 3.5.0, for the Google Cloud Spanner Data .NET library.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eKeySet\u003c/code\u003e class is an immutable class used to define a set of keys for selecting data from a table or index in Google Cloud Spanner, specifically within read operations.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eKeySet\u003c/code\u003e instances can be created using individual keys, key ranges, or the \u003ccode\u003eAll\u003c/code\u003e property, which is used to select all rows in a table.\u003c/p\u003e\n"],["\u003cp\u003eThe class provides properties like \u003ccode\u003eAllKeys\u003c/code\u003e, \u003ccode\u003eKeys\u003c/code\u003e, and \u003ccode\u003eRanges\u003c/code\u003e to check if all rows are selected and to access the specific keys or ranges that are part of the set.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eKeySet\u003c/code\u003e class offers methods like \u003ccode\u003eFromKeys\u003c/code\u003e, \u003ccode\u003eFromParameters\u003c/code\u003e, and \u003ccode\u003eFromRanges\u003c/code\u003e for constructing different types of key sets, as well as \u003ccode\u003eToString\u003c/code\u003e for diagnostic representation, and is part of the \u003ccode\u003eGoogle.Cloud.Spanner.Data\u003c/code\u003e namespace.\u003c/p\u003e\n"]]],[],null,["# Google.Cloud.Spanner.Data - Class KeySet (5.1.0)\n\nVersion latestkeyboard_arrow_down\n\n- [5.1.0 (latest)](/dotnet/docs/reference/Google.Cloud.Spanner.Data/latest/Google.Cloud.Spanner.Data.KeySet)\n- [5.0.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/5.0.0/Google.Cloud.Spanner.Data.KeySet)\n- [4.6.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/4.6.0/Google.Cloud.Spanner.Data.KeySet)\n- [4.5.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/4.5.0/Google.Cloud.Spanner.Data.KeySet)\n- [4.4.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/4.4.0/Google.Cloud.Spanner.Data.KeySet)\n- [4.3.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/4.3.0/Google.Cloud.Spanner.Data.KeySet)\n- [4.2.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/4.2.0/Google.Cloud.Spanner.Data.KeySet)\n- [4.1.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/4.1.0/Google.Cloud.Spanner.Data.KeySet)\n- [4.0.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/4.0.0/Google.Cloud.Spanner.Data.KeySet)\n- [3.15.1](/dotnet/docs/reference/Google.Cloud.Spanner.Data/3.15.1/Google.Cloud.Spanner.Data.KeySet)\n- [3.14.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/3.14.0/Google.Cloud.Spanner.Data.KeySet)\n- [3.13.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/3.13.0/Google.Cloud.Spanner.Data.KeySet)\n- [3.12.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/3.12.0/Google.Cloud.Spanner.Data.KeySet)\n- [3.11.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/3.11.0/Google.Cloud.Spanner.Data.KeySet)\n- [3.10.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/3.10.0/Google.Cloud.Spanner.Data.KeySet)\n- [3.9.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/3.9.0/Google.Cloud.Spanner.Data.KeySet)\n- [3.8.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/3.8.0/Google.Cloud.Spanner.Data.KeySet)\n- [3.7.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/3.7.0/Google.Cloud.Spanner.Data.KeySet)\n- [3.6.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/3.6.0/Google.Cloud.Spanner.Data.KeySet)\n- [3.5.0](/dotnet/docs/reference/Google.Cloud.Spanner.Data/3.5.0/Google.Cloud.Spanner.Data.KeySet) \n\n public sealed class KeySet\n\nReference documentation and code samples for the Google.Cloud.Spanner.Data class KeySet.\n\nImmutable class that defines a set of keys to select from a table or index.\nKeySets are used for Read operations to specify the rows that should be returned\nby the read. A KeySet can be created from a set of individual keys or a set of\nkey ranges. The [All](/dotnet/docs/reference/Google.Cloud.Spanner.Data/latest/Google.Cloud.Spanner.Data.KeySet#Google_Cloud_Spanner_Data_KeySet_All) instance can be used for read operations\nthat should return all rows. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e KeySet \n\nInherited Members\n-----------------\n\n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Cloud.Spanner.Data](/dotnet/docs/reference/Google.Cloud.Spanner.Data/latest/Google.Cloud.Spanner.Data)\n\nAssembly\n--------\n\nGoogle.Cloud.Spanner.Data.dll\n\nExample\n-------\n\nExample usage: \n\n using var cmd = connection.CreateReadCommand(\n \"MyTable\",\n ReadOptions.FromColumns(\"MyCol1\", \"MyCol2\"),\n KeySet.FromKeys(new Key(\"k1\"), new Key(\"k2\")));\n using var reader = await cmd.ExecuteReaderAsync();\n\nProperties\n----------\n\n### All\n\n public static KeySet All { get; }\n\nReturns a key set that selects all keys in the table or index.\n\n### AllKeys\n\n public bool AllKeys { get; }\n\nTrue for key sets that select all keys in the table or index, and false for all other key sets.\n\n### Keys\n\n public IEnumerable\u003cKey\u003e Keys { get; }\n\nThe collection of specific keys to select.\n\n### Ranges\n\n public IEnumerable\u003cKeyRange\u003e Ranges { get; }\n\nThe list of key ranges to select. All rows that are in at least one of the key ranges will be selected.\n\nMethods\n-------\n\n### FromKeys(params Key\\[\\])\n\n public static KeySet FromKeys(params Key[] keys)\n\nCreates a new key set for a collection of keys.\n\n### FromParameters(SpannerParameterCollection)\n\n public static KeySet FromParameters(SpannerParameterCollection parameters)\n\nCreates a new key set from a collection of parameters that represent exactly one key.\n\n### FromRanges(params KeyRange\\[\\])\n\n public static KeySet FromRanges(params KeyRange[] ranges)\n\nCreates a new key set for a collection of key ranges.\n\n### ToString(SpannerConnectionStringBuilder)\n\n public string ToString(SpannerConnectionStringBuilder builder)\n\nReturns the string representation of this KeySet using the type conversion options specified in\n[SpannerConnectionStringBuilder](/dotnet/docs/reference/Google.Cloud.Spanner.Data/latest/Google.Cloud.Spanner.Data.SpannerConnectionStringBuilder). The string representation is only for diagnostic purposes\nand the implementation may change over time."]]