public void One_way_parent_to_child_relation_of_a_joined_table_can_be_loaded_with_another_join() { var artist1 = new Artist("artist 1"); var artist2 = new Artist("artist 2"); var album1 = new Album("album 1"); var album2 = new Album("album 2"); var track1 = new Track("track 1"); var track2 = new Track("track 2"); var track3 = new Track("track 3"); Repository.Insert(artist1, artist2); album1.ArtistId = artist1.Id; album2.ArtistId = artist2.Id; Repository.Insert(album1, album2); track1.AlbumId = album1.Id; track2.AlbumId = album1.Id; track3.AlbumId = album2.Id; Repository.Insert(track1, track2, track3); var actualArtist = Repository.Find<Artist>() .Where(x => x.Id == artist1.Id) .Join<Artist, Album>(x => x.Albums, x => x.ArtistId) .Join<Album, Track>(x => x.Tracks, x => x.AlbumId) .OrderBy<Album>(x => x.Title) .OrderBy<Track>(x => x.Title) .Execute(); Assert.AreEqual("artist 1", actualArtist.Name); Assert.AreEqual(1, actualArtist.Albums.Count); Assert.AreEqual("album 1", actualArtist.Albums[0].Title); Assert.AreEqual(2, actualArtist.Albums[0].Tracks.Count); Assert.AreEqual("track 1", actualArtist.Albums[0].Tracks[0].Title); Assert.AreEqual("track 2", actualArtist.Albums[0].Tracks[1].Title); }
public void Parent_entity_with_collection_navigation_property_can_be_joined_to_child_entity_without_navigation_property_but_with_foreign_key_property() { var album1 = new Album { Title = "Album 1" }; var album2 = new Album { Title = "Album 2" }; var track1 = new Track { Title = "Track 1" }; var track2 = new Track { Title = "Track 2" }; var track3 = new Track { Title = "Track 3" }; album1.Tracks.Add(track1); album1.Tracks.Add(track3); album2.Tracks.Add(track2); Repository.Insert(album1, album2); track1.AlbumId = album1.Id; track3.AlbumId = album1.Id; track2.AlbumId = album2.Id; Repository.Insert(track1, track2, track3); var actualAlbum = Repository .Find<Album>() .Join<Track>(x => x.Tracks, x => x.AlbumId) .OrderBy<Track>(x => x.Title) .Where(x => x.Title == "Album 1").Execute(); Assert.AreEqual(album1, actualAlbum); }
public void Entity_with_navigation_property_cah_be_joined_to_entity_without_collection_property() { var review1 = new AlbumReview { Title = "Title 1" }; var review2 = new AlbumReview { Title = "Title 2" }; var album1 = new Album { Title = "Album 1" }; var album2 = new Album { Title = "Album 2" }; review1.Album = album1; review2.Album = album2; Repository.Insert(album1, album2); Repository.Insert(review1, review2); var actualReview = Repository.Find<AlbumReview>().Join<Album>(x => x.Album).Where(x => x.Title == "Title 1").Execute(); Assert.AreEqual(review1, actualReview); }