Realms sync and object inheritance

HI guys.

I have a .net maui (so we’re talking C# / .net) project in which I want to implement mongodb atlas device sync: my data model is composed by two classes (LockerEntry and LockerItemEntry) that inherits from a common parent (DbEntry) that inherits from RealmObject (pretty straightforward).
My realm app (the one created from the web mongo dashboard) has the developer mode on, because I want schema and db collection to be generated from my data model.

Now, what i’m experiencing is that, when running my .net maui app, DbEntry collection and schema are created just fine (in fact, this is unwanted, but i’ve already figured out that annotating the class with Realms.Ignored attribute will prevent it), whereas LockerEntry and LockerItemEntry are not, while realm initialization throws an error saying “The class LockerEntry is not in the limited set of classes for this realm (Parameter ‘T’)”.

Making LockerEntry and LockerItemEntry inherit directly from RealmObject instead of DbEntry would work, but then I should duplicate the code contained in DbEntry parent class, and I’d rather not do that…

May you please provide some suggestions?

This is a known limitation of Realm - we don’t currently support inheritance, so you’d need to either duplicate the properties across LockerEntry and LockerItemEntry or use composition, where DbEntry is an embedded object contained by the other two.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.