99:其中一个请求输入无效。
上述消息中的 99 表示您的批次中的第 100 个实体存在错误(索引从 0 开始)。您可以检查的几件事:
- 确保实体数据正确。
- 由于您正在执行“添加”操作,因此请确保该实体不存在。除了“添加”操作,您还可以尝试插入或替换实体或插入或合并实体操作。
看看下面的代码:
public class CustomerEntity : TableServiceEntity
{
public CustomerEntity()
{
PartitionKey = "Customer";
RowKey = Guid.NewGuid().ToString();
}
public string FirstName
{
get;
set;
}
public string LastName
{
get;
set;
}
public DateTime? LastOrderDate
{
get;
set;
}
}
static void InsertEntityBatchOperation()
{
var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
var cloudTableClient = storageAccount.CreateCloudTableClient();
var customer = new CustomerEntity()
{
FirstName = "John",
LastName = "Smith",
LastOrderDate = DateTime.UtcNow.Date.AddDays(-10)
};
var serviceContext = cloudTableClient.GetDataServiceContext();
serviceContext.AddObject(tableName, customer);
customer = new CustomerEntity()
{
FirstName = "Jane",
LastName = "Smith",
LastOrderDate = DateTime.UtcNow.Date.AddDays(-5)
};
serviceContext.AttachTo(tableName, customer, null);
serviceContext.UpdateObject(customer);
customer = new CustomerEntity()
{
FirstName = "John",
LastName = "Doe",
LastOrderDate = DateTime.UtcNow.Date.AddDays(-7)
};
serviceContext.AttachTo(tableName, customer, null);
serviceContext.UpdateObject(customer);
customer = new CustomerEntity()
{
FirstName = "Jane",
LastName = "Doe",
LastOrderDate = DateTime.UtcNow.Date.AddDays(-3)
};
serviceContext.AttachTo(tableName, customer, null);
serviceContext.UpdateObject(customer);
//Following will perform Insert Or Merge Entity Operation
serviceContext.SaveChangesWithRetries(SaveChangesOptions.Batch);
//Following will perform Insert Or Replace Entity Operation
serviceContext.SaveChangesWithRetries(SaveChangesOptions.Batch | SaveChangesOptions.ReplaceOnUpdate);
}