realm / realm-dotnet

Realm is a mobile database: a replacement for SQLite & ORMs

Home Page:https://realm.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

uixiu opened this issue · comments

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

➤ PM Bot commented:

Jira ticket: RNET-1146

When I compile my project against x64, the program behaves as expected
Going back to x86, causes collections bindings and SubscribeForNotifications issues reappear.

Are you running the x86 version on an x86 machine or on a x64 one?

Are you running the x86 version on an x86 machine or on a x64 one?

Thanks for your reply
I am running the x86 version on an x64 machine (Windows 11-x64, intel 12900H processor)

Okay, I can reproduce this running x86 on Arm64 - will try and investigate further.