实体不会从Azure表中删除
本文关键字:删除 Azure 实体 | 更新日期: 2023-09-27 18:29:19
当我试图删除实体时,Visual Studio总是在"serviceContext.DeleteObject(entity);"行上崩溃,并说"上下文当前没有跟踪实体。"有人知道为什么以及如何修复它吗?
CloudTableQuery<ScheduleEntity> query = scheduleManNot.retrieveSchedule();
//Checks every entry
foreach (ScheduleEntity entity in query)
{
comparison = System.DateTime.Compare(entity.eventTime, time);
if (comparison <= 0)
{
changeConfirmation = scheduleManNot.changeInstanceCount(entity.subscriptionID, entity.amount, entity.serviceName);
if (changeConfirmation == false)
{
Console.WriteLine("Configuration Change failed");
}
if (changeConfirmation == true)
{
Console.WriteLine("Configuration Change Succeeded");
Console.WriteLine(entity.serviceName + " had its instance count changed to " + entity.amount);
serviceContext.AttachTo("schedule", entity, "*");
serviceContext.DeleteObject(entity);
//Submit the operation to the table service
serviceContext.SaveChangesWithRetries();
由于您通过查询接收实体,因此不需要附加实体。因此,我认为这里根本不需要附件,正如你在评论中所说的那样。如果需要删除未附着的图元,可以先将其附着并标记为已删除。