Просто для дальнейшего использования, если у других возникнет такая же проблема
Это то, что сработало для меня.
[FunctionName("WebrootConnector")]
public static void Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
[CosmosDB(
databaseName: "customersDB",
collectionName: "customers",
ConnectionStringSetting = "CosmosDBConnection",
Id = "999"
)]
Customers customersObject, // in binding
[CosmosDB(
databaseName: "customersDB",
collectionName: "customers",
CreateIfNotExists = true,
ConnectionStringSetting = "CosmosDBConnection"
)]
out Customers customersDocumentToDB, // out binding
ILogger log)
{
if (customersObject == null)
{
// Create a new Customers object
customersObject = new Customers();
// Set the id of the database document (should always be the same)
customersObject.Id = "999";
// Create a new empty customer list on the customers object
customersObject.customers = new List<Customer>();
}
else
{
// if a object is received from the database
// do something with it.
}
if (customersObject.customers != null)
{
// Write the object back to the cosmosDB collection
customersDocumentToDB = customersObject;
log.LogInformation($"Data written to customerDB");
}
else
{
customersDocumentToDB = null;
log.LogInformation($"Nothing to write to database");
}
}
Класс Customer:
public class Customers
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("lastUpdated")]
public System.DateTime lastUpdated { get; set; }
[JsonProperty("customers")]
public List<Customer> customers { get; set; }
}
public class Customer
{
[JsonProperty("customerId")]
public int customerID { get; set; }
[JsonProperty("customerName")]
public string customerName { get; set; }
[JsonProperty("customerKeycode")]
public string customerKeyCode { get; set; }
}
После добавления привязок, одного для входных данных и одного для выходных данных, и изменения моего параметра id класса CustomersObject на строку вместо int все работало нормально, за исключением того, что в привязке in всегда возвращался CustomersObject = null, даже если у меня в коллекции был документ сid = "999", созданный привязкой out.
Я обнаружил, что решение для меня - удалить коллекцию в моем cosmosDB на портале Azure и добавить CreateIfNotExists = true в привязку out.Это позволяет привязке out создавать коллекцию без PartitionKey (что невозможно из портала Azure через веб-интерфейс, так как это требуется), а затем удаляет PartitionKey = "/ id" из привязки in.
Теперь все работает как положено: -)
Может быть, я неправильно использовал PartitionKey? ...