{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-dotnet/issues/743","repository_url":"https://api.github.com/repos/realm/realm-dotnet","labels_url":"https://api.github.com/repos/realm/realm-dotnet/issues/743/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-dotnet/issues/743/comments","events_url":"https://api.github.com/repos/realm/realm-dotnet/issues/743/events","html_url":"https://github.com/realm/realm-dotnet/issues/743","id":168663890,"number":743,"title":"Deletion from a filtered query result - Potentially does not perform delete","user":{"login":"m-mccool","id":19569386,"avatar_url":"https://avatars.githubusercontent.com/u/19569386?v=3","gravatar_id":"","url":"https://api.github.com/users/m-mccool","html_url":"https://github.com/m-mccool","followers_url":"https://api.github.com/users/m-mccool/followers","following_url":"https://api.github.com/users/m-mccool/following{/other_user}","gists_url":"https://api.github.com/users/m-mccool/gists{/gist_id}","starred_url":"https://api.github.com/users/m-mccool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-mccool/subscriptions","organizations_url":"https://api.github.com/users/m-mccool/orgs","repos_url":"https://api.github.com/users/m-mccool/repos","events_url":"https://api.github.com/users/m-mccool/events{/privacy}","received_events_url":"https://api.github.com/users/m-mccool/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-08-01T14:47:08Z","updated_at":"2016-08-01T16:40:34Z","closed_at":null,"body":"\r\n#### Goal\r\n\r\nWhen attempting to delete a list of RealmObjects from a query result,  to know if it has not successfully deleted all the objects returned in the query\r\n\r\n#### Expected Results\r\n\r\nAll the RealmObjects in the query are deleted \r\n\r\n#### Actual Results\r\n\r\nNot all the RealmObjects are deleted\r\n\r\n#### Steps & Code to Reproduce\r\n\r\nSee the code below. \r\n\r\n```\r\nvar filteredObjects = realm.All<MyRealmObject>().Where(x => x.FieldOne == false\r\n                        && x.FieldTwo == \"someText\");\r\n                        foreach (var realmObject in filteredObjects)\r\n                        {\r\n                            realm.Remove(realmObject);\r\n                        }\r\n```\r\nWhat I find is that not all the reamlObjects are being removed/deleted. If I debug it I see the foreach loop exiting before all the objects in the filteredObjects list is processed. To fix it I had to put .ToList() at the end of the query as shown below.\r\n\r\n```\r\nvar filteredObjects = realm.All<MyRealmObject>().Where(x => x.FieldOne == false\r\n                        && x.FieldTwo == \"someText\").ToList();\r\n                        foreach (var realmObject in filteredObjects)\r\n                        {\r\n                            realm.Remove(realmObject);\r\n                        }\r\n```\r\n\r\nI think this may be a silent fail of trying to delete from an IEnumerable as you loop through it. If this is the case it should throw an exception.\r\n\r\nVersion of Realm and tooling\r\n\r\nRealm 0.77.1\r\n\r\nVisual Studio 2015 Update 3 v14.0.25424.00 with\r\nXamrin 4.1.1.3\r\nXamarin Android 6.1.1.1\r\nXamarin iOS 9.8.1.4\r\n\r\nXamarin Studio\r\n=== Xamarin Studio Community ===\r\n\r\nVersion 6.0.1 (build 8)\r\nInstallation UUID: c0a4c8dc-0061-4b22-a3ad-b4e6bc68b1db\r\nRuntime:\r\nMono 4.4.1 (mono-4.4.0-branch-c7sr0/4747417) (64-bit)\r\nGTK+ 2.24.23 (Raleigh theme)\r\n\r\nPackage version: 404010000\r\n=== Xamarin.Profiler ===\r\n\r\nVersion: 0.31.0\r\nLocation: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler\r\n\r\n=== Xamarin.Android ===\r\n\r\nVersion: 6.1.1.1 (Xamarin Studio Community)\r\nAndroid SDK: /Users/Username/Library/Developer/Xamarin/android-sdk-macosx\r\nSupported Android versions:\r\n2.3 (API level 10)\r\n4.0.3 (API level 15)\r\n4.4 (API level 19)\r\n5.0 (API level 21)\r\n6.0 (API level 23)\r\n\r\nSDK Tools Version: 24.4.1\r\nSDK Platform Tools Version: 23.0.1\r\nSDK Build Tools Version: 23.0.1\r\n\r\nJava SDK: /usr\r\njava version \"1.8.0_101\"\r\nJava(TM) SE Runtime Environment (build 1.8.0_101-b13)\r\nJava HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)\r\n\r\nAndroid Designer EPL code available here:\r\nhttps://github.com/xamarin/AndroidDesigner.EPL\r\n\r\n=== Xamarin Android Player ===\r\n\r\nNot Installed\r\n\r\n=== Apple Developer Tools ===\r\n\r\nXcode 7.3.1 (10188.1)\r\nBuild 7D1014\r\n\r\n=== Xamarin.Mac ===\r\n\r\nVersion: 2.8.1.4 (Xamarin Studio Community)\r\n\r\n=== Xamarin.iOS ===\r\n\r\nVersion: 9.8.1.4 (Xamarin Studio Community)\r\nHash: 3cf8aae\r\nBranch: c7sr0\r\nBuild date: 2016-06-20 16:09:58-0400\r\n\r\n=== Build Information ===\r\n\r\nRelease ID: 600010008\r\nGit revision: 0ecc3639cde21616d675e4fdef1b858d166dd065\r\nBuild date: 2016-06-20 13:16:51-04\r\nXamarin addins: a9252e6df4851fbbed1f9c6228e7b6dd1b475ac5\r\nBuild lane: monodevelop-lion-cycle7-sr0\r\n\r\n=== Operating System ===\r\n\r\nMac OS X 10.11.5\r\nDarwin W013208-MAC 15.5.0 Darwin Kernel Version 15.5.0\r\nTue Apr 19 18:36:36 PDT 2016\r\nroot:xnu-3248.50.21~8/RELEASE_X86_64 x86_64\r\n\r\nWhich operating system version and device: \r\niOS targetting 9.0.0\r\nDevice running 9.2.1\r\nMac OS X El Capitan\r\nWindows 7"},"comment":{"url":"https://api.github.com/repos/realm/realm-dotnet/issues/comments/236635750","html_url":"https://github.com/realm/realm-dotnet/issues/743#issuecomment-236635750","issue_url":"https://api.github.com/repos/realm/realm-dotnet/issues/743","id":236635750,"user":{"login":"m-mccool","id":19569386,"avatar_url":"https://avatars.githubusercontent.com/u/19569386?v=3","gravatar_id":"","url":"https://api.github.com/users/m-mccool","html_url":"https://github.com/m-mccool","followers_url":"https://api.github.com/users/m-mccool/followers","following_url":"https://api.github.com/users/m-mccool/following{/other_user}","gists_url":"https://api.github.com/users/m-mccool/gists{/gist_id}","starred_url":"https://api.github.com/users/m-mccool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-mccool/subscriptions","organizations_url":"https://api.github.com/users/m-mccool/orgs","repos_url":"https://api.github.com/users/m-mccool/repos","events_url":"https://api.github.com/users/m-mccool/events{/privacy}","received_events_url":"https://api.github.com/users/m-mccool/received_events","type":"User","site_admin":false},"created_at":"2016-08-01T16:40:34Z","updated_at":"2016-08-01T16:40:34Z","body":"Just working through your comments so I've got it straight\r\n\r\nMy understanding is that because an IQueryable is returned from the Where clause, then it is acting against the realm e.g. each time I would do a foreach it would query the realm. \r\n\r\nSo it seems like the MoveNext is skipping objects because the RealmObject has been removed  from the IQueryable when the call to Remove happens.\r\n\r\nI guess the problem is that you cannot tell the difference between someone iterating and updating an object, and someone iterating and deleting an object.\r\n\r\nIs an easier option to provide a method that takes the list of object someone want to delete. At least it would take away some of possibility of it happening. You can bet people will write their own method to do this any way. My first thought was to look for a Remove method on the API that does this"}}
{"actor":{"display_login":"m-mccool"}}