Uploaded image for project: 'Realm .NET SDK'
  1. Realm .NET SDK
  2. RNET-1087

Unable to delete items using realm.RemoveRange

    • Type: Icon: Task Task
    • Resolution: Works as Designed
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: None
    • Component/s: None

      What happened?

      Unable to delete items using realm range, when using .Where(predicate) to retrieve results from realm.all
      Below is the code used to fetch items and delete items in a range.

      IEnumerable<T> entities = realm.All<T>().Where(predicate);
      realm.RemoveRange(entities.AsQueryable());
      

      The realm.all<T> will return a valid Queryable however, with LINQ Where will return an IEnumerable so this causes the result entities cannot be passed as to RemoveRange where as per docs https://www.mongodb.com/docs/realm/sdk/dotnet/crud/delete/ it should be valid. If this is not valid, please update the docs. Thus, the conversion to AsQueryable()

      Causing an exception

      {System.ArgumentException: range should be the return value of .All or a LINQ query applied to it. (Parameter 'range')
      

      As per checking the resource https://github.com/realm/realm-dotnet/blob/main/Realm/Realm/Realm.cs

      var results = Argument.EnsureType<RealmResults<T>>(range, "range should be the return value of .All or a LINQ query applied to it.", nameof(range));
      

      Ensures that the type is realm results – which is an IQueryable argument.

      Removing the Where clause ensures that the range is valid, thus not causing any Exceptions

      Repro steps

      • Delete item using range

      Version

      10.19.0

      What Atlas Services are you using?

      Local Database only

      What type of application is this?

      Xamarin

      Client OS and version

      Android 12.0

      Code snippets

      No response

      Stacktrace of the exception/crash you're getting

      No response

      Relevant log output

      No response

            Assignee:
            nikola.irinchev@mongodb.com Nikola Irinchev
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: