Created
October 20, 2020 05:05
-
-
Save PradeepLoganathan/22cee392729ad67a9245f72d5a25bc3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<List<Order>> GetOrders(string customerId) | |
{ | |
try | |
{ | |
var sqlQueryText = "SELECT * FROM c WHERE c.CustomerId = @customerid"; | |
Console.WriteLine("Running query: {0}\n", sqlQueryText); | |
QueryDefinition queryDefinition = new QueryDefinition(sqlQueryText).WithParameter("@customerid", "CU7-36-8183" ); | |
FeedIterator<Order> queryResultSetIterator = this._container.GetItemQueryIterator<Order>(queryDefinition); | |
List<Order> orders = new List<Order>(); | |
while (queryResultSetIterator.HasMoreResults) | |
{ | |
FeedResponse<Order> currentResultSet = await queryResultSetIterator.ReadNextAsync(); | |
foreach (Order order in currentResultSet) | |
{ | |
orders.Add(order); | |
Console.WriteLine("\tRead {0}\n", order.OrderId); | |
} | |
} | |
return orders; | |
} | |
catch (CosmosException ex) | |
{ | |
Console.WriteLine("Exception occured in GetCustomer: {0} Message body is {1}.\n", ex.Message,ex.ResponseBody); | |
throw ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment