实体不会从Azure表中删除

时间:2012-03-29 12:11:58

标签: c# azure entity

当我尝试删除实体时,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();

1 个答案:

答案 0 :(得分:1)

由于您通过查询接收实体,因此无需附加实体。 因此,我认为这里根本没有必要,因为你在评论中已经说过了。 如果您需要删除未附加的实体,可以先将其附加,并将标记删除。