- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从 azure 函数 .net 5.0 中的 azure cosmos db 获取项目但我收到此错误,因为我使用异步方法
Feedlterator <rsakeys> Container.GetitemQuerylterator <rsakeys> (QueryDefinition queryDefinition, [string continuation Token = null], [QueryRequestOptions requestOptions = null]) (+ 1 overload) This method creates a query for items under a container in an Azure Cosmos database using a SQL statement with parameterized values. It returns a Feedlterator. For more information on preparing SQL statements with parameterized values, please see QueryDefinition.
Returns:
An iterator to go through the items. CS8411: Asynchronous foreach statement cannot operate on variables of type 'Feediterator <rsakeys>' because 'Feedlterator <rsakeys>' does not contain a suitable public instance or extension definition for 'GetAsyncEnumerator
CS8411: Asynchronous foreach statement cannot operate on variables of type 'Feediterator <rsakeys>' because 'Feedlterator <rsakeys>' does not contain a suitable public instance or extension definition for 'GetAsyncEnumerator
这是我的代码,我根本没有找到任何关于此错误的好的文档,我几乎迷失了。
namespace projectA
{
class projectA
{
[Function("projectA")]
async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "")] HttpRequestData req,
FunctionContext context)
{
var logger = context.GetLogger("projectA");
logger.LogInformation("C# HTTP trigger function processed a request.");
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
/// The Azure Cosmos DB endpoint.
string EndpointUrl = "https://name.documents.azure.com:443/";
/// The primary key for the Azure DocumentDB account.
string PrimaryKey = "primarykey";
// The Cosmos client instance
CosmosClient cosmosClient = new CosmosClient(EndpointUrl, PrimaryKey);
Database database;
Container container;
string databaseId = "database1";
string containerId = "container1";
var sqlQueryText = "SELECT * FROM c WHERE c.key = '123'";
Console.WriteLine("Running query: {0}\n", sqlQueryText);
container = cosmosClient.GetContainer(databaseId, containerId);
QueryDefinition queryDefinition = new QueryDefinition(sqlQueryText);
List<rsakeys> rsakeyss = new List<rsakeys>();
//In this await foreach i get the error...
await foreach (rsakeys RsaKeys in container.GetItemQueryIterator<rsakeys>(queryDefinition))
{
rsakeyss.Add(RsaKeys);
Console.WriteLine("\tRead {0}\n", RsaKeys);
}
}
}
}
最佳答案
用于 Feed 迭代器的模式是
while (feedIterator.HasMoreResults)
foreach (var item in await feedIterator.ReadNextAsync())
Console.Write(item.Cost);
如果您想使用等待的 foreach (又名 IAsynEnumerable
),您可以推出自己的 IAsynEnumerable
产量
private static async IAsyncEnumerable<T> SomeMethod<T>(
Container container,
QueryDefinition queryDefinition,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
using var feedIterator = container.GetItemQueryIterator<T>(queryDefinition);
while (feedIterator.HasMoreResults)
foreach (var item in await feedIterator
.ReadNextAsync(cancellationToken)
.ConfigureAwait(false))
yield return item;
}
使用
await foreach(var item in SomeMethod<SomeType>(container, queryDefinition)
Console.Write(item);
<小时/>
额外事实
还值得注意的是ReadNextAsync
返回Task<FeedResponse<T>>
public abstract Task<FeedResponse<T>> ReadNextAsync(CancellationToken cancellationToken = default);
FeedResponse
继承自 Response
FeedResponse<T> : Response<IEnumerable<T>>, IEnumerable<T>
但是,为了方便起见Response
有一个隐式运算符,因此可以隐式转换为其通用 Enumerbale 类型 IEnumerable<T>
public static implicit operator T(Response<T> response)
因此,以下两种说法均有效
using var feedIterator = container.GetItemQueryIterator<Bob>(queryDefinition);
FeedResponse<Bob> bobResponse = await feedIterator.ReadNextAsync()
IEnumerable<Bob> bobs = await feedIterator.ReadNextAsync()
根据评论更新
After doing using
var feedIterator = container.GetItemQueryIterator<rsakeys>(queryDefinition); var x =
await feedIterator.ReadNextAsync();
Console.WriteLine(x.GetType().ToString());I get this console output :
Microsoft.Azure.Cosmos.QueryResponse`1[PolarisRSAFunction1NET5.rsakeys]
how do i access the query value?
调用ReadNextAsync
将返回 FeedResponse<rsakeys>
从那里您可以调用 x.Resource
返回IEnumerable<rsakeys>
或者直接赋值
即
var response = await feedIterator.ReadNextAsync();
IEnumerable<rsakeys> items = response.Resource;
关于c# - Cosmos DB 和 Azure 函数 Get item .net 5 异步 foreach 语句无法对 FeedIterator 类型的变量进行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68155231/
这里我试图在 FlatList 中显示一个名为“posts”的数组。 render() { console.log(this.props.posts); return (
这是我的代码: {{day(list)}} {{list.weather[0].description}}
我是 Mahout 的新手,并且仍在使用它。 我的问题是,将 Item-Item 和 User-Item 结合起来是否合适? 我的用例是,一个社交网络应用会尝试根据用户历史数据(优先级较高)为当前用户
下午好, 我按数据库搜索以测试特定类测试,当我放置一个新项目时,如果列表包含该项目。 @Test public void insertAndDeleteTask() throws Interrupte
我有一个关于 ionic 框架的问题,我希望有人能帮助我...我有一个带有“ion-item-right”的 ionic 列表。这一切都可以,按钮在右边。现在我需要其他三个居中的图标,这样我就有了:文
我经常遇到类似下面的代码: if ( items != null) { foreach(T item in items) { //... } } 基本上,if 条件确
我最近问了a question about LocalStorage .使用 JSON.parse(localStorage.item) 和 JSON.parse(localStorage['item
我最近问了a question about LocalStorage .使用 JSON.parse(localStorage.item) 和 JSON.parse(localStorage['item
这个问题已经有答案了: Type mismatch: cannot convert from Item to Item (1 个回答) 已关闭 7 年前。 我很困惑。我无法将外部类的实例变量 Node
我目前正在使用 MUI Grid(但我对替代解决方案持开放态度)并且我想要并排放置两个组件:最右边的组件占 400px宽度和左侧组件占据其余部分。 || || || 当页面宽度缩小时: | | ||
我最近问过a question about LocalStorage 。使用 JSON.parse(localStorage.item) 和 JSON.parse(localStorage['item
public class Document extends Model { ... @ManyToMany public Set accessors; ... } 我想选择访问者包含某个用户的所有文档
我正在使用 selenium webdriver 为单页 Web 应用程序开发一个 Java 框架,使用以下模式:PageObject、SlowLoadableComponent(责任链)、PageF
最近在学习C,在网上发现了一个问题。问题是: What is the problem with this function in terms of memory allocation? What is
我有这个代码 ( -1 ? true : false} /> {genre.item.name}
在ASP.Net中使用DataGrid时真的没有快捷方法吗 (e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.A
我正在使用工作流程根据数据和一组要求将大量 pdf 从一个位置复制到其他大坝位置。我正在使用以下代码 Assets damAsset = manager.createAsset(path, is, m
我是 PowerShell 的新手。 我正在尝试自动将 dll 组件从源服务器上的文件夹部署到目标服务器上的多个文件夹。这看起来应该很简单:将组件从源服务器上的源(部署)文件夹复制到目标服务器上的文件
我的代码: for column_name, column_data in summary_words.iteritems(): if column_name != "summary" and
我的代码: for column_name, column_data in summary_words.iteritems(): if column_name != "summary" and
我是一名优秀的程序员,十分优秀!