public void should_explicit_load_everything_if_joined() { var db = Mocker.Resolve <IDatabase>(); var files = MediaFileRepository.Query(db, new SqlBuilder() .Join <BookFile, Edition>((t, a) => t.EditionId == a.Id) .Join <Edition, Book>((e, b) => e.BookId == b.Id) .Join <Book, Author>((book, author) => book.AuthorMetadataId == author.AuthorMetadataId) .Join <Author, AuthorMetadata>((a, m) => a.AuthorMetadataId == m.Id)); Assert.IsNotEmpty(files); foreach (var file in files) { Assert.IsTrue(file.Edition.IsLoaded); Assert.IsTrue(file.Author.IsLoaded); Assert.IsTrue(file.Author.Value.Metadata.IsLoaded); } }
public void should_explicit_load_everything_if_joined() { var db = Mocker.Resolve <IDatabase>(); var files = MediaFileRepository.Query(db, new SqlBuilder() .Join <TrackFile, Track>((f, t) => f.Id == t.TrackFileId) .Join <TrackFile, Album>((t, a) => t.AlbumId == a.Id) .Join <Album, Artist>((album, artist) => album.ArtistMetadataId == artist.ArtistMetadataId) .Join <Artist, ArtistMetadata>((a, m) => a.ArtistMetadataId == m.Id)); Assert.IsNotEmpty(files); foreach (var file in files) { Assert.IsTrue(file.Tracks.IsLoaded); Assert.IsNotEmpty(file.Tracks.Value); Assert.IsTrue(file.Album.IsLoaded); Assert.IsTrue(file.Artist.IsLoaded); Assert.IsTrue(file.Artist.Value.Metadata.IsLoaded); } }
public static void Map() { RegisterMappers(); Mapper.Entity <Config>("Config").RegisterModel(); Mapper.Entity <RootFolder>("RootFolders").RegisterModel() .Ignore(r => r.Accessible) .Ignore(r => r.FreeSpace) .Ignore(r => r.TotalSpace); Mapper.Entity <ScheduledTask>("ScheduledTasks").RegisterModel(); Mapper.Entity <IndexerDefinition>("Indexers").RegisterModel() .Ignore(x => x.ImplementationName) .Ignore(i => i.Enable) .Ignore(i => i.Protocol) .Ignore(i => i.SupportsRss) .Ignore(i => i.SupportsSearch) .Ignore(d => d.Tags); Mapper.Entity <ImportListDefinition>("ImportLists").RegisterModel() .Ignore(x => x.ImplementationName) .Ignore(i => i.Enable) .Ignore(i => i.ListType); Mapper.Entity <NotificationDefinition>("Notifications").RegisterModel() .Ignore(x => x.ImplementationName) .Ignore(i => i.SupportsOnGrab) .Ignore(i => i.SupportsOnReleaseImport) .Ignore(i => i.SupportsOnUpgrade) .Ignore(i => i.SupportsOnRename) .Ignore(i => i.SupportsOnHealthIssue) .Ignore(i => i.SupportsOnDownloadFailure) .Ignore(i => i.SupportsOnImportFailure) .Ignore(i => i.SupportsOnTrackRetag); Mapper.Entity <MetadataDefinition>("Metadata").RegisterModel() .Ignore(x => x.ImplementationName) .Ignore(d => d.Tags); Mapper.Entity <DownloadClientDefinition>("DownloadClients").RegisterModel() .Ignore(x => x.ImplementationName) .Ignore(d => d.Protocol) .Ignore(d => d.Tags); Mapper.Entity <History.History>("History").RegisterModel(); Mapper.Entity <Artist>("Artists") .Ignore(s => s.RootFolderPath) .Ignore(s => s.Name) .Ignore(s => s.ForeignArtistId) .HasOne(a => a.Metadata, a => a.ArtistMetadataId) .HasOne(a => a.QualityProfile, a => a.QualityProfileId) .HasOne(s => s.MetadataProfile, s => s.MetadataProfileId) .LazyLoad(a => a.Albums, (db, a) => db.Query <Album>(new SqlBuilder().Where <Album>(rg => rg.ArtistMetadataId == a.Id)).ToList(), a => a.Id > 0); Mapper.Entity <ArtistMetadata>("ArtistMetadata").RegisterModel(); Mapper.Entity <Album>("Albums").RegisterModel() .Ignore(x => x.ArtistId) .HasOne(r => r.ArtistMetadata, r => r.ArtistMetadataId) .LazyLoad(a => a.AlbumReleases, (db, album) => db.Query <AlbumRelease>(new SqlBuilder().Where <AlbumRelease>(r => r.AlbumId == album.Id)).ToList(), a => a.Id > 0) .LazyLoad(a => a.Artist, (db, album) => ArtistRepository.Query(db, new SqlBuilder() .Join <Artist, ArtistMetadata>((a, m) => a.ArtistMetadataId == m.Id) .Where <Artist>(a => a.ArtistMetadataId == album.ArtistMetadataId)).SingleOrDefault(), a => a.ArtistMetadataId > 0); Mapper.Entity <AlbumRelease>("AlbumReleases").RegisterModel() .HasOne(r => r.Album, r => r.AlbumId) .LazyLoad(x => x.Tracks, (db, release) => db.Query <Track>(new SqlBuilder().Where <Track>(t => t.AlbumReleaseId == release.Id)).ToList(), r => r.Id > 0); Mapper.Entity <Track>("Tracks").RegisterModel() .Ignore(t => t.HasFile) .Ignore(t => t.AlbumId) .HasOne(track => track.AlbumRelease, track => track.AlbumReleaseId) .HasOne(track => track.ArtistMetadata, track => track.ArtistMetadataId) .LazyLoad(t => t.TrackFile, (db, track) => MediaFileRepository.Query(db, new SqlBuilder() .Join <TrackFile, Track>((l, r) => l.Id == r.TrackFileId) .Join <TrackFile, Album>((l, r) => l.AlbumId == r.Id) .Join <Album, Artist>((l, r) => l.ArtistMetadataId == r.ArtistMetadataId) .Join <Artist, ArtistMetadata>((l, r) => l.ArtistMetadataId == r.Id) .Where <TrackFile>(t => t.Id == track.TrackFileId)).SingleOrDefault(), t => t.TrackFileId > 0) .LazyLoad(x => x.Artist, (db, t) => ArtistRepository.Query(db, new SqlBuilder() .Join <Artist, ArtistMetadata>((a, m) => a.ArtistMetadataId == m.Id) .Join <Artist, Album>((l, r) => l.ArtistMetadataId == r.ArtistMetadataId) .Join <Album, AlbumRelease>((l, r) => l.Id == r.AlbumId) .Where <AlbumRelease>(r => r.Id == t.AlbumReleaseId)).SingleOrDefault(), t => t.Id > 0); Mapper.Entity <TrackFile>("TrackFiles").RegisterModel() .HasOne(f => f.Album, f => f.AlbumId) .LazyLoad(x => x.Tracks, (db, file) => db.Query <Track>(new SqlBuilder().Where <Track>(t => t.TrackFileId == file.Id)).ToList(), x => x.Id > 0) .LazyLoad(x => x.Artist, (db, f) => ArtistRepository.Query(db, new SqlBuilder() .Join <Artist, ArtistMetadata>((a, m) => a.ArtistMetadataId == m.Id) .Join <Artist, Album>((l, r) => l.ArtistMetadataId == r.ArtistMetadataId) .Where <Album>(a => a.Id == f.AlbumId)).SingleOrDefault(), t => t.Id > 0); Mapper.Entity <QualityDefinition>("QualityDefinitions").RegisterModel() .Ignore(d => d.GroupName) .Ignore(d => d.GroupWeight) .Ignore(d => d.Weight); Mapper.Entity <QualityProfile>("QualityProfiles").RegisterModel(); Mapper.Entity <MetadataProfile>("MetadataProfiles").RegisterModel(); Mapper.Entity <Log>("Logs").RegisterModel(); Mapper.Entity <NamingConfig>("NamingConfig").RegisterModel(); Mapper.Entity <Blacklist>("Blacklist").RegisterModel(); Mapper.Entity <MetadataFile>("MetadataFiles").RegisterModel(); Mapper.Entity <LyricFile>("LyricFiles").RegisterModel(); Mapper.Entity <OtherExtraFile>("ExtraFiles").RegisterModel(); Mapper.Entity <PendingRelease>("PendingReleases").RegisterModel() .Ignore(e => e.RemoteAlbum); Mapper.Entity <RemotePathMapping>("RemotePathMappings").RegisterModel(); Mapper.Entity <Tag>("Tags").RegisterModel(); Mapper.Entity <ReleaseProfile>("ReleaseProfiles").RegisterModel(); Mapper.Entity <DelayProfile>("DelayProfiles").RegisterModel(); Mapper.Entity <User>("Users").RegisterModel(); Mapper.Entity <CommandModel>("Commands").RegisterModel() .Ignore(c => c.Message); Mapper.Entity <IndexerStatus>("IndexerStatus").RegisterModel(); Mapper.Entity <DownloadClientStatus>("DownloadClientStatus").RegisterModel(); Mapper.Entity <ImportListStatus>("ImportListStatus").RegisterModel(); Mapper.Entity <CustomFilter>("CustomFilters").RegisterModel(); Mapper.Entity <ImportListExclusion>("ImportListExclusions").RegisterModel(); }