在函数中显式地将字符串转换为GUID。例如,使用Guid.Parse()
方法将字符串转换为GUID。示例代码如下:
public static async Task Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
[CosmosDB(
databaseName: "database-name",
collectionName: "collection-name",
ConnectionStringSetting = "connection-string",
Id = "{Query.id}",
PartitionKey = "{Query.partitionKey}")] MyObject inputDocument,
ILogger log)
{
// Convert string id to Guid
if(Guid.TryParse(req.Query["id"], out Guid id))
{
inputDocument.Id = id;
}
else
{
return new BadRequestObjectResult("Invalid id parameter");
}
// rest of the function code
// ...
return new OkObjectResult("Success");
}