简体   繁体   English

查询以从 Cosmos DB 获取详细信息

[英]Query to fetch details from Cosmos DB

I need to fetch the list of persons from an array(Ex: String[] getPersons ) as input.我需要从数组(例如: String[] getPersons )中获取人员列表作为输入。 I can't figure out how to compare and fetch data from Cosmos DB using a LINQ expression.我不知道如何使用 LINQ 表达式从 Cosmos DB 比较和获取数据。 I experimented with GetItemLinqQueryable , but I don't know if it's the right way to use it.我尝试了GetItemLinqQueryable ,但我不知道它是否是正确的使用方法。

var db = Client.GetDatabase(databaseId);

var container = db.GetContainer(containerId);

var q = container.GetItemLinqQueryable<Person>();

var iterator = q.Where(p => p.Name == getPersons[0]).ToFeedIterator();

var results = await iterator.ReadNextAsync();

If I am using the above one, I could only able to get only the first person result but I need to get the other persons in the array as well.如果我使用上面的那个,我只能得到第一人称的结果,但我也需要得到数组中的其他人。

You can use Contains.您可以使用包含。 It is equivalent to ARRAY_CONTAINS in Cosmos DB Array functions.它等效于 Cosmos DB 数组函数中的ARRAY_CONTAINS

You can try this code:你可以试试这段代码:

var iterator = q.Where(p => getPersons.Contains(p.Name)).ToFeedIterator();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM