StevenR
StevenR

Reputation: 445

Entity wont delete from Azure Table

when i try to delete the entity Visual Studio keeps crashing on the line "serviceContext.DeleteObject(entity);"and saying "The context is not currently tracking the entity." Has anyone any ideas why and how to fix it?

    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();

Upvotes: 1

Views: 1036

Answers (1)

daryal
daryal

Reputation: 14919

Since you are receiving the entity over a query, you do not need to attach the entity. Thus I think here attachto is not needed at all as you have stated in the comment. If you need to delete an unattached entity, you can first attach it and mark is as deleted.

Upvotes: 1

Related Questions