Reputation: 149
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.
Upvotes: 0
Views: 545
Reputation: 8660
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();
Upvotes: 1