FrankE
FrankE

Reputation: 313

Windows Azure TableServiceContext UndoChanges

When trying to save an object using an illegal character (e.g. '/') in the RowKey an exception is thrown when calling

_tableServiceContext.AddObject(tableName, myEntity);

I get an System.Data.Services.Client.DataServiceRequestException with the info "out of range", which is easily prevented (by preventing or checking for illegal characters).

My question now is, how do I recover from this status? After such an error all succeeding AddObject calls fail, presumably because the "corrupt object" still belong to the context.

Therefore I'm looking for a "UndoChanges" possibility.

Any hints are appreciated, thanks.

P.S.: I'm looking for a better way than to throw away the context or to delete the object from the context...

Upvotes: 0

Views: 91

Answers (1)

Brian Reischl
Brian Reischl

Reputation: 7356

The best way is probably to detach the entity from the context. If that's not an option for some reason, you could retry the save with SaveChangesOption.ContinueOnErrors set. eg,

_tableServiceContext.SaveChangesWithRetries(SaveChangesOptions.ContinueOnError);

This basically applies all the updates one at a time, instead of in batches. Note it will ignore all errors that occur, not just the one from the illegal entity.

Upvotes: 1

Related Questions