Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 云firestore,其中方法在.Net中不起作用_C#_.net Core_Google Cloud Firestore_Firebase Cli - Fatal编程技术网

C# 云firestore,其中方法在.Net中不起作用

C# 云firestore,其中方法在.Net中不起作用,c#,.net-core,google-cloud-firestore,firebase-cli,C#,.net Core,Google Cloud Firestore,Firebase Cli,我正在使用.net core中的google.cloud.firestore包,我想查询在提供的值列表中存在特定字段值的文档(如sql中的in命令)。我遇到了方法,其中方法,但我一直得到一个异常。过去几个小时我一直在努力,但没有成功 代码如下: public async Task<List<Document>> GetListByAccountRef(List<string> accountRefs) { var docRef =

我正在使用
.net core
中的
google.cloud.firestore
包,我想查询在提供的值列表中存在特定字段值的文档(如sql中的
in
命令)。我遇到了
方法,其中
方法,但我一直得到一个异常。过去几个小时我一直在努力,但没有成功
代码如下:

   public async Task<List<Document>> GetListByAccountRef(List<string> accountRefs)
    {
        var docRef = _Firestore.Collection("documents").WhereIn("AccountRef", accountRefs);
        var docsQuery = await docRef.GetSnapshotAsync();
        var docs = docsQuery.Select(d => d.ConvertTo<Document>()).ToList();
        return docs;
    }
这是stacktrace:

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Grpc.Core.Internal.ClientResponseStream`2.<MoveNext>d__5.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Linq.AsyncEnumerable.<ForEachAsync_>d__174`1.MoveNext() in 
D:\a\1\s\Ix.NET\Source\System.Interactive.Async\ForEach.cs:line 141
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Cloud.Firestore.Query.<GetSnapshotAsync>d__54.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Docer.DAL.Repositories.DocumentRepository.<GetListByAccountRef>d__7.MoveNext() in E:\Docer\webapp- 
FireStore-Branch\Docer.DAL\Repositories\Document\DocumentRepository.cs:line 84
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Docer.BLL.Doc.DocumentBusiness.<GetUserDocuments>d__10.MoveNext() in E:\Docer\webapp-FireStore- 
Branch\Docer.BLL.Doc\Document\DocumentBusiness.cs:line 84
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()中
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在Grpc.Core.Internal.ClientResponseStream`2.d_u5.MoveNext()中
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()中
在System.Linq.AsyncEnumerable.d_u174`1.MoveNext()中
D:\a\1\s\Ix.NET\Source\System.Interactive.Async\ForEach.cs:第141行
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()中
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在Google.Cloud.Firestore.Query.d_u54.MoveNext()上
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()中
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()中
在E:\Docer\webapp-
FireStore Branch\Docer.DAL\Repositories\Document\DocumentRepository.cs:第84行
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()中
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()中
在E:\Docer\webapp FireStore-
Branch\Docer.BLL.Doc\Document\DocumentBusiness.cs:第84行

感谢您的帮助。

多亏了Jon,问题似乎来自我使用的firestore仿真器的旧版本。更新模拟器后,它工作正常。

这对我来说很有效。您可以按照教程()进行操作

List cities=新列表()
{
新城市()
{
CityName=“测试”
}
};
Query employeeQuery=fireStoreDb.Collection(name of(Employee))。其中(“城市”,cities);
QuerySnapshot employeeQuerySnapshot=等待employeeQuery.GetSnapshotAsync();

这显然令人惊讶。我已经存档了,明天再查。@JonSkeet非常感谢你,Jon!我无法在我的系统上复制这个。我在本期中添加了一个示例程序-您可以尝试一下,并让我知道它是否适用于您吗?(可能值得在这个问题上来回做所有剩余的工作;当我们知道发生了什么时,我们可以在这里添加一个答案。)正如在本期文章中所指出的,这似乎是一个与旧模拟器运行的问题。谢谢你的时间Jon,我会检查它。
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Grpc.Core.Internal.ClientResponseStream`2.<MoveNext>d__5.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Linq.AsyncEnumerable.<ForEachAsync_>d__174`1.MoveNext() in 
D:\a\1\s\Ix.NET\Source\System.Interactive.Async\ForEach.cs:line 141
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Cloud.Firestore.Query.<GetSnapshotAsync>d__54.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Docer.DAL.Repositories.DocumentRepository.<GetListByAccountRef>d__7.MoveNext() in E:\Docer\webapp- 
FireStore-Branch\Docer.DAL\Repositories\Document\DocumentRepository.cs:line 84
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Docer.BLL.Doc.DocumentBusiness.<GetUserDocuments>d__10.MoveNext() in E:\Docer\webapp-FireStore- 
Branch\Docer.BLL.Doc\Document\DocumentBusiness.cs:line 84
                List<Cities> cities = new List<Cities>()
                {
                    new Cities()
                    {
                        CityName="tests"
                    }
                };
                Query employeeQuery = fireStoreDb.Collection(nameof(Employee)).WhereIn("City", cities);
                QuerySnapshot employeeQuerySnapshot = await employeeQuery.GetSnapshotAsync();