locked
Cannot delete a row in Azure Table RRS feed

  • Question

  • User-2089506584 posted

    Error is "The context is not currently tracking the entity."

    Dim myAccount As CloudStorageAccount = 'connection-to-cloud-table'
    Dim clientTable = myAccount.CreateCloudTableClient()
    Dim serviceContextTable = clientTable.GetDataServiceContext()
    
    Dim query As CloudTableQuery(Of NOrthwind) = _
    (From ent In serviceContextTable.CreateQuery(Of NOrthwind)("azure-table-name-here")
    Where ent.PartitionKey = "test-partitionKey" And ent.RowKey = "test-rowKey").AsTableServiceQuery()
    
    serviceContextTable.DeleteObject(query) '<<<--error here
    serviceContextTable.SaveChangesWithRetries()


    Why I get such error? I only want to delete a single row.

    Thursday, July 4, 2013 10:57 AM

Answers

All replies

  • User-183374066 posted

    I guess query is return Array of objects .. You have to loop through to delete record

    See here Delete Entities in Azure Table Storage

    or

    @{
    WindowsAzureStorage.DeleteRow("NewSampleTable", "partition1", "row1");
    } 

    See http://azurestoragehelper.codeplex.com/documentation

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 4, 2013 4:03 PM
  • User-2089506584 posted

    You have to loop through to delete record

    You are right. Below is the working code.

    Dim myAccount As CloudStorageAccount = 'connection-to-cloud-table'
    Dim clientTable = myAccount.CreateCloudTableClient()
    Dim serviceContextTable = clientTable.GetDataServiceContext()
    
    Dim query As CloudTableQuery(Of NOrthwind) = _
    (From ent In serviceContextTable.CreateQuery(Of NOrthwind)("azure-table-name-here")
    Where ent.PartitionKey = "test-partitionKey" And ent.RowKey = "test-rowKey").AsTableServiceQuery()
    
    For Each itemDelete In query '<<---enclose in a loop
    	serviceContextTable.DeleteObject(itemDelete) '<<---working delete goes here
    	serviceContextTable.SaveChangesWithRetries()
    Next

    Thanks Nasser!

    Friday, July 5, 2013 2:45 AM