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

RealmResults (from Realm live queries) no longer notify UI observers

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None

      What happened?

      I am not sure if this is a bug or a feature side effect, anyway I'm building a significant product feature (live queries) based on the previous version's behavior. Feel free to change Label accordingly.
      This is a miniature project for example usage

      Consider the attached code snippets or linked example project;

      Before version 12.0.0 ( <= 11.7.0), when adding or deleting objects to database, the list box is populated and updated correctly,
      When upgraded to version 12.0.0 or above, the listbox is neither populated nor updated after object removal. On my full-fledged project, list boxes and data grids are sometimes populated, but are not always updated after deletions.

      Repro steps

      Compile and run linked example projects(Visual Studio 2022 is required for WinUI )

      Version

      12.1.0

      What Atlas Services are you using?

      Local Database only

      What type of application is this?

      Other

      Client OS and version

      Windows 11 Pro 23H2 - 22631.3447

      Code snippets

      public partial class Cat : IRealmObject
      {
          [PrimaryKey]
          public ObjectId Id { get; set; } = ObjectId.GenerateNewId();
          public string Name { get; set; } = string.Empty;
          public int Age { get; set; } = 0;
          public string Breed { get; set; } = string.Empty;
      }
      
       public partial class MainWindowViewModel : ObservableObject
       {
           public MainWindowViewModel()
           {
               var config = new RealmConfiguration(@"d:\temp\cats.realm");
               _localRealm = Realm.GetInstance(config);
               CatsQuery = _localRealm.All<Cat>();
           }
      
           private Realm _localRealm;
      
           [ObservableProperty] 
           private IQueryable<Cat> _catsQuery;
           
           public Cat? SelectedCat { get; set; }
      
           [RelayCommand]
           private void RemoveCat()
           {
               if (SelectedCat == null)
                   return;
               _localRealm.Write(() => { _localRealm.Remove(SelectedCat); });
           }
      
           [RelayCommand]
           public void Populate()
           {
               Cat ninja = new() { Name = "Ninja", Age = 1, Breed = "Angora" };
               Cat nounou = new() { Name = "Nounou", Age = 2, Breed = "Siamese" };
      
               _localRealm.Write(() => _localRealm.Add(nounou));
               _localRealm.Write(() => _localRealm.Add(ninja));
           }
       }
      
      <Window
          x:Class="RealmWinUI.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          mc:Ignorable="d">
      
          <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
              <Button Content="Populate" Command="{x:Bind MainViewModel.PopulateCommand}" />
              <Button Content="Delete" Command="{x:Bind MainViewModel.RemoveCatCommand}" />
      
              <ListBox ItemsSource="{x:Bind  MainViewModel.CatsQuery}"
                       DisplayMemberPath="Name"
                       SelectedItem="{x:Bind MainViewModel.SelectedCat, Mode=TwoWay}"/>
          </StackPanel>
      </Window>
      

      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:
            2 Start watching this issue

              Created:
              Updated: