Reputation: 5857
When running this code in cloud service project in VS2013, I get 404 error.
How is it possible that I am deleting a row that does not exist while I am retrieving it from the table?
var routeResultQuery = new TableQuery<RouteResult>(); // I deleted where caluse for brevity
var results = resultTable.ExecuteQuery<RouteResult>(routeResultQuery).ToList();
if (results.Count() > 0) // The count shows 26 element when debugging
{
foreach(RouteResult rr in results)
{
var op = TableOperation.Delete(rr);
resultTable.Execute(op); // The error happens here
}
}
Upvotes: 1
Views: 546
Reputation: 5857
It turned out that I badly designed the table so that RowKey is overwritten twice when constructed by the retrieving method.
public class RouteResult : TableEntity
{
public string Session
{
get
{
return PartitionKey;
}
set
{
RowKey = value + "-" + DateTime.UtcNow.Ticks; // The issue is here
PartitionKey = value;
}
}
}
The issue is not really in the overwriting operation but in the variable value DateTime.UtcNow.Ticks
that result in a different RowKey, thus 404 not found.
I changed the table to:
public class RouteResult : TableEntity
{
public RouteResult(string sessionId)
{
RowKey = sessionId + "-" + Guid.NewGuid();
PartitionKey = sessionId;
}
public RouteResult()
{
}
}
And now it is fine.
Upvotes: 1