There is a nascent C# SDK you could grab; check out Jon Skeet's repo here: http://jskeet.github.io/google-cloud-dotnet/docs/Google.Cloud.Firestore.Data/
(The following is from GitHub)
Installation
Install the Google.Cloud.Firestore.Data
package from NuGet. Add it to your project in the normal way (for example by right-clicking on the project in Visual Studio and choosing "Manage NuGet Packages..."). Please ensure you enable pre-release packages(for example, in the Visual Studio NuGet user interface, check the "Include prerelease" box).
Authentication
When running on Google Cloud Platform, no action needs to be taken to authenticate.
Otherwise, the simplest way of authenticating your API calls is to download a service account JSON file then set the GOOGLE_APPLICATION_CREDENTIALS
environment variable to refer to it. The credentials will automatically be used to authenticate. See the Getting Started With Authentication guide for more details.
Getting started
Everything starts with FirestoreDb. Create an instance using the Create
or CreateAsync
methods, passing in your Google Cloud project ID. The default credentials will be used to authenticate with the server.
From there, you can create, fetch and modify documents, and run queries.
Sample code
FirestoreDb db = FirestoreDb.Create(projectId);
// Create a document with a random ID in the "users" collection.
CollectionReference collection = db.Collection("users");
DocumentReference document = await collection.AddAsync(new { Name = new { First = "Ada", Last = "Lovelace" }, Born = 1815 });
// A DocumentReference doesn't contain the data - it's just a path.
// Let's fetch the current document.
DocumentSnapshot snapshot = await document.SnapshotAsync();
// We can access individual fields by dot-separated path
Console.WriteLine(snapshot.GetField<string>("Name.First"));
Console.WriteLine(snapshot.GetField<string>("Name.Last"));
Console.WriteLine(snapshot.GetField<int>("Born"));
// Or deserialize the whole document into a dictionary
Dictionary<string, object> data = snapshot.ToDictionary();
Dictionary<string, object> name = (Dictionary<string, object>) data["Name"];
Console.WriteLine(name["First"]);
Console.WriteLine(name["Last"]);
// See the "data model" guide for more options for data handling.
// Query the collection for all documents where doc.Born < 1900.
Query query = collection.Where("Born", QueryOperator.LessThan, 1900);
QuerySnapshot querySnapshot = await query.SnapshotAsync();
foreach (DocumentSnapshot queryResult in querySnapshot.Documents)
{
string firstName = queryResult.GetField<string>("Name.First");
string lastName = queryResult.GetField<string>("Name.Last");
int born = queryResult.GetField<int>("Born");
Console.WriteLine($"{firstName} {lastName}; born {born}");
}