internal void LoadRoots(ModelTransaction transaction) { // Exit immediately if roots have already been loaded if (Roots != null) { return; } // Create an array of roots to be loaded Roots = new ModelInstance[Ids == null ? 0 : Ids.Length]; // Get the root instances for (int i = 0; i < Roots.Length; i++) { // Create the root instance Roots[i] = transaction == null?From.Create(Ids[i]) : transaction.GetInstance(From, Ids[i]); } // Access a property to force the instance to initialize. Do a seperate pass so batched loading will work. for (int i = 0; i < Roots.Length; i++) { var initProp = Roots[i].Type.Properties.FirstOrDefault(p => p is ModelValueProperty) ?? Roots[i].Type.Properties.FirstOrDefault(p => p is ModelReferenceProperty); if (initProp == null) { throw new Exception(string.Format("Type \"{0}\" cannot be forced to initialize because it has no properties.", Roots[i].Type.Name)); } Roots[i].OnPropertyGet(initProp); } }