我正在尝试使用带有Nugget软件包Google.Cloud.Firestore的Firestore
我关注了此简介CRUD with firestore
使用调试器,我看到尝试调用方法Query.GetSnapshotAsync()时程序的执行停止了>
我只想从集合中获取文档列表。
Controller
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Web.Http; using System.Web.Http.Results; using FirestoreAPI.Domain.Restaurants; using FirestoreAPI.Repository.Restaurants; using System.Threading.Tasks; namespace FirestoreAPI.Controllers { [RoutePrefix("api")] public class RestaurantsController : ApiController { public RestaurantsController() { } [HttpGet] [Route("restaurants")] public IHttpActionResult GetAllRestaurants() { //var restAggregate = new RestaurantsAggregate(); var restaurantsRepo = new RestaurantsRepo(); return new NegotiatedContentResult<Task<List<Restaurant>>>( HttpStatusCode.OK, restaurantsRepo.GetAllRestaurants(), this ); ; } } }
DataLayer
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Web; using Google.Cloud.Firestore; namespace FirestoreAPI.Repository.Restaurants { public class RestaurantsRepo { //public FirestoreConn dbConn; string projectId; FirestoreDb firestoreDb; public RestaurantsRepo() { //dbConn = new FirestoreConn(); string credentials = "C:\\Users\\ezequiel.lopez\\projects\\firestoredotnet\\FirestoreAPI\\firestoreapi-dca55-0be2f7d57f41.json"; Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credentials); projectId = "firestoreapi-dca55"; firestoreDb = FirestoreDb.Create(projectId); } public async Task<List<Restaurant>> GetAllRestaurants() { //FirestoreDb fsDB = dbConn.GetFSConnection(); //Query query = fsDB.Collection("restaurants").OrderByDescending("avgRating").Limit(50); Query query = firestoreDb.Collection("restaurants").OrderByDescending("avgRating").Limit(50); QuerySnapshot restSnaps = await query.GetSnapshotAsync(); List<Restaurant> restaurants = new List<Restaurant>(); return restSnaps.Documents .Where<DocumentSnapshot>(ds => ds.Exists) .Select(ds => ds.ConvertTo<Restaurant>()).ToList(); } } }
餐厅
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Google.Cloud.Firestore;
namespace FirestoreAPI.Repository.Restaurants
{
[FirestoreData]
public class Restaurant
{
[FirestoreProperty]
public decimal avgRating { get; set; }
[FirestoreProperty]
public string category { get; set; }
[FirestoreProperty]
public string city { get; set; }
[FirestoreProperty]
public string name { get; set; }
[FirestoreProperty]
public int numRatings { get; set; }
[FirestoreProperty]
public int price { get; set; }
}
}
我正在尝试使用掘金软件包Google.Cloud.Firestore尝试Firestore,并使用firestore跟随了此介绍性CRUD使用调试器,我发现尝试调用...时程序的执行停止了。 [