要检查实体是否存在,您可以将其作为输入参数接受并测试null
:
[FunctionName("UpsertEntity")]
public static HttpResponseMessage Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route="test/{id}")]
HttpRequestMessage req,
string id,
[Table("Test", "default", "{id}")] MyEntity entity)
{
return req.CreateResponse(HttpStatusCode.OK, entity != null ? "exists" : "not found");
}
您可以使用输入和输出参数的组合进行 upsert:
[FunctionName("UpsertEntity")]
public static HttpResponseMessage Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route="test/{id}")]
HttpRequestMessage req,
string id,
[Table("Test", "default", "{id}")] MyEntity entity,
[Table("Test", "default", "{id}")] out MyEntity outEntity)
{
outEntity = entity ?? new MyEntity { PartitionKey = "default", RowKey = id };
outEntity.Name = Guid.NewGuid().ToString();
return req.CreateResponse(HttpStatusCode.OK, id);
}