0
votes

I'm developing an application, that allows using dictionaries (e.g. English - German or Country - Capital). There are just 2 very plain tables:

1) Dictionary:

int Id, string Title //PartitionKey="SomeConstString", Rowkey=Id.ToString()

2) Article:

int DictionaryId, string Word, string Meaning //PartitionKey="D" + DictionaryID, Rowkey=Word

I can add articles, but when trying to delete I get the following problem: in every dictionary one or two articles are not deleted. Instead I get ResourceNotFoundException. There is absolutely nothing special about those articles (e.g. Russia - Moscow). When I try to add articles with same PartitionKey and RowKey I get EntityAlreadyExistsException. I installed "Cloud Storage Studio" and found out that those entities are really still in table. I tried to delete them manually but got the same ResourceNotFoundException in storage studio that I was getting in code. So if I add 100 articles and then try to delete them (in code or in studio like Ctrl+A -> Delete), 99 (or sometimes 98) are deleted and others are not. I'm using development storage emulator. Here is how I remove articles (I tried different approaches, result is still the same):

public void DeleteAllArticlesFromDictionary(int dictionaryID) {
            TableServiceContext tableServiceContext = tableClient.GetDataServiceContext();            
            string partitionKey = "D" + dictionaryID;            
            Article[] articles = tableServiceContext.CreateQuery<Article>(articleTableName).Where(a => a.PartitionKey == partitionKey).ToArray();
            for (int i = 0; i<articles.Length; ++i) 
                tableServiceContext.DeleteObject(articles[i]);                     
            tableServiceContext.SaveChanges();        
        }

Can anyone tell me what can possibly be wrong with this? UPD: Works fine in Cloud

1
Can you give specific examples of PartitionKey/RowKey combos that aren't deleting? Is it always the same rows or keys that have problems, or is it sometimes a different row?Brian Reischl
I attached screenshots and some extra explanations to the same question posted at msdn. Link: social.msdn.microsoft.com/Forums/en-EN/windowsazuredata/thread/…Oleg Golovkov
That is really weird. Perhaps your devstorage just got into a weird state? Try deleting the table, then recreate it and see if it behaves the same.Brian Reischl
I tried recreating tables, restarting emulator and even rebooting. For now I think, this is some kind of weird storage emulator bug, perhaps caused by getting hash codes from these specific strings or something. I published my app and it works just fine in real environment. I'll try to use another values as keys for articles and see if something changesOleg Golovkov
by recreating tables do you mean you opened the GUI for the storage emulator and selected reset from the menu?cory-fowler

1 Answers

0
votes

I think I found the problem, there was a space character (0x20, ' ') in the end of the word which is RowKey. So it was say 'RowKey1 '. I removed space and now everything is fine in devstorage too (it was not a problem in real environment). However it is rather confusing that spaces are treated correctly inside the key (say 'Row Key 1' can be used without errors) but cause such behaviour if are trailing characters (or maybe leading too). I've read about 'Characters Disallowed in Key Fields', but spaces were not mentioned there. I guess I should use Trim() for my strings before using them as keys.