gpt4 book ai didi

c# - 实体不会从 Azure 表中删除

转载 作者:行者123 更新时间:2023-12-03 03:20:27 24 4
gpt4 key购买 nike

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

最佳答案

由于您是通过查询接收实体,因此无需附加实体。因此,我认为这里根本不需要 Attachto,正如您在评论中所述。如果需要删除未附加的实体,可以先附加它,然后将其标记为已删除。

关于c# - 实体不会从 Azure 表中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9925041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com