private static void AddChildObjects(IAlbum album) { if (album == null) throw new ArgumentNullException("album"); #region Add child albums using (var repo = new AlbumRepository()) { //foreach (int albumId in GetDataProvider().Album_GetChildAlbumIdsById(album.Id)) foreach (int albumId in repo.Where(a => a.FKAlbumParentId == album.Id).Select(a => a.AlbumId)) { album.AddGalleryObject(CreateAlbumInstance(albumId, album.GalleryId)); } } #endregion #region Add child media objects using (var repo = new MediaObjectRepository()) { //foreach (MediaObjectDto moDto in GetDataProvider().Album_GetChildMediaObjectsById(album.Id, album.AllowMetadataLoading)) IQueryable<MediaObjectDto> moDtos; if (album.AllowMetadataLoading) moDtos = repo.Where(m => m.FKAlbumId == album.Id, m => m.Metadata); else moDtos = repo.Where(m => m.FKAlbumId == album.Id); foreach (MediaObjectDto moDto in moDtos) { var mediaObject = GetMediaObjectFromDto(moDto, album); AddToMediaObjectCache(mediaObject); album.AddGalleryObject(mediaObject); } } #endregion album.AreChildrenInflated = true; }