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

[Bug]: `EmbeddedObject.Parent` returning `null`

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: API

      What happened?

      EmbeddedObject.Parent is not returning anything after being added to realm

      Repro steps

      1. Create a new RealmObject() with an EmbeddedObject, IList<EmbeddedObject, or IDictionary<TKey, EmbeddedObject> property
      2. Add RealmObject to Realm
      3. Populate the aforementioned property with a new EmbeddedObject()
      4. Accessing the Parent property of the added EmbeddedObject returns null

      Version

      10.7.1

      What SDK flavour are you using?

      Local Database only

      What type of application is this?

      Console/Server

      Client OS and version

      Windows 10 Home 20H2 19042.1348

      Code snippets

      Here's a small program for reproducing the bug

      Unable to find source-code formatter for language: cs. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      public class Test_EmbeddedObjects {
      
          class Item : RealmObject {
              public string? Label { get; set; }
              public ChildItem? ChildItem { get; set; }
              public IList<ChildItem> ChildItemList { get; } = null!;
              public IDictionary<string, ChildItem> ChildItemDict { get; } = null!;
          }
      
          class ChildItem : EmbeddedObject {
              public string? Label { get; set; }
          }
      
          public static void Main() {
              var config = new InMemoryConfiguration( "meemoo.db" ) {
                  Schema = new Type[] { typeof( Item ), typeof( ChildItem ) }
              };
              var realm = Realm.GetInstance( config );
      
              var item = new Item { Label = "A" };
              item.ChildItem = new ChildItem { Label = "b" };
              realm.Write( () => {
                  realm.Add( item );
                  item.ChildItemList.Add( new ChildItem { Label = "c" } );
                  item.ChildItemDict.Add( "d", new ChildItem { Label = "d" } );
              } );
      
              Console.WriteLine( item.ChildItem.Parent != null); // False
              Console.WriteLine( item.ChildItemList.First().Parent != null); // False
              Console.WriteLine( item.ChildItemDict.Values.First().Parent != null); // False
          }
      }
      

      Stacktrace of the exception/crash you're getting

      No response

      Relevant log output

      No response

            Assignee:
            ferdinando.papale@mongodb.com Ferdinando Papale
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: