Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
769 views
in Technique[技术] by (71.8m points)

azure - Query to fetch details from Cosmos DB

I need to fetch the list of persons from an array(Ex: String[] getPersons) as input. I can't figure out how to compare and fetch data from Cosmos DB using a LINQ expression. I experimented with GetItemLinqQueryable, but I don't know if it's the right way to use it.

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.

question from:https://stackoverflow.com/questions/65858741/query-to-fetch-details-from-cosmos-db

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use Contains. It is equivalent to ARRAY_CONTAINS in Cosmos DB Array functions.

You can try this code:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...