List property of RealmObject is empty


#1

I am trying to create an object with an IList property, but when I write this object to the DB, this property becomes empty.
Object class:

public class MarkModel : RealmObject
    {
        [PrimaryKey]
        public string id { get; set; }
        public ModuleModel module { get; set; }
        public string professor { get; set; }
        public IList<WeekMarks> mark { get; }

        public MarkModel(ModuleModel module, string professor, List<WeekMarks> mark)
        {
            this.module = module;
            this.professor = professor;
            this.mark = mark;
            id = module.p1 + module.p2;
        }

WeekMarks class:

public class WeekMarks : RealmObject
    {
        public string week { get; set; }
        public string type { get; set; }
        public string percent { get; set; }
        public IList<string> marks { get; }

        public WeekMarks()
        {
            week = "";
            percent = "";
            type = "";
            marks = new List<string>();
        }

Read method:

        public static RealmObject ReadModuleMarksDB(string key)
        {
            return Database.Find<MarkModel>(key);
        }

Write Method:

public static bool WriteN(MarkModel model)
        {
            try
            {
                using (var trans = Database.BeginWrite())
                {
                    Database.Add(model);
                    trans.Commit();
                }
                return true;
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to write MarkModel: " + ex.InnerException);
            }
        }

View of Realm Studio:


View of Object in Visual Studio:

The main problem is that when the object is read from DB, mark.Count is always zero, it is empty, but if you look at Realm Studio, mark property is properly linked.
Do I missed something or just not properly implemented the data classes?


#2

One obvious issue is that you shouldn’t assign a new List to the property - Realm will generate the backing field for you with the correct type. If you need to populate it with some values, you can copy the items from the mark argument to the property.


#3

Thank you for the answer, somehow I missed it. But now, when I want to see contents of List, Result View throws this message:


Is there any other way to see List contents?

EDIT:
Solved it. Sorry, forgot, that I need to do Linq Query to view contents