예제 #1
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]
        }