예제 #1
0
        private static async Task GetDocAsMap(string project)
        {
            FirestoreDb db = FirestoreDb.Create(project);
            // [START fs_get_doc_as_map]
            DocumentReference docRef   = db.Collection("cities").Document("SF");
            DocumentSnapshot  snapshot = await docRef.SnapshotAsync();

            if (snapshot.Exists)
            {
                Console.WriteLine("Document data for {0} document:", snapshot.Id);
                Dictionary <string, object> city = snapshot.ToDictionary();
                foreach (KeyValuePair <string, object> pair in city)
                {
                    Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
                }
            }
            else
            {
                Console.WriteLine("Document {0} does not exist!", snapshot.Id);
            }
            // [END fs_get_doc_as_map]
        }
예제 #2
0
        private static async Task GetDocAsEntity(string project)
        {
            FirestoreDb db = FirestoreDb.Create(project);
            // [START fs_get_doc_as_entity]
            DocumentReference docRef   = db.Collection("cities").Document("BJ");
            DocumentSnapshot  snapshot = await docRef.SnapshotAsync();

            if (snapshot.Exists)
            {
                Console.WriteLine("Document data for {0} document:", snapshot.Id);
                City city = snapshot.Deserialize <City>();
                Console.WriteLine("Name: {0}", city.Name);
                Console.WriteLine("State: {0}", city.State);
                Console.WriteLine("Country: {0}", city.Country);
                Console.WriteLine("Capital: {0}", city.Capital);
                Console.WriteLine("Population: {0}", city.Population);
            }
            else
            {
                Console.WriteLine("Document {0} does not exist!", snapshot.Id);
            }
            // [END fs_get_doc_as_entity]
        }