gpt4 book ai didi

c# - 尝试通过 MVC 应用程序通过 client.CreateDocumentQuery 从 CosmosDb 获取对象

转载 作者:行者123 更新时间:2023-12-03 07:07:16 30 4
gpt4 key购买 nike

首次尝试访问 Cosmos 数据库。

所有这些都位于解决方案的 DAL 项目层(n 层)中。EndPointURI、PrimaryKey 和 DBName 由类构造函数设置。

我执行client.CreateDocumentQuery

但没有看到预期的函数输出参数的转换,即“用户”。我只看到生成的查询字符串。

我的代码基于 this

public void  GetUserByEmail(string email, out IQueryable<Shared.User> user)
{
FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1 };
user = null;

try
{
user = this.client.CreateDocumentQuery<Shared.User>(
UriFactory.CreateDocumentCollectionUri(DBName, "Users"), queryOptions)
.Where(f => f.Email == email);
}
catch (Exception ex)
{
}

}

enter image description here

如果尝试 ReadDocumentAsync,我会得到以下信息 enter image description here

最佳答案

试试这个,你需要返回第一个项目

 var response = this.client.CreateDocumentQuery<eUser>( UriFactory.CreateDocumentCollectionUri("demo", "Users"), queryOptions) 
.Where(f => f.Email == email).AsEnumerable().ToArray().FirstOrDefault();

关于c# - 尝试通过 MVC 应用程序通过 client.CreateDocumentQuery 从 CosmosDb 获取对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71204661/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com