私は最後に内部結合を使用してから何年も経っているので、少し錆びています。3つのテーブルがあります
アルバム、AlbumsImages、ユーザー
さて、最初に私のリポジトリでi Inner Left Join Album and AlbumsImages、事は私が最初のカバー説明、次にID説明によるalbumsimagesからの最初のエンターテインメントだけが欲しいということです(AlbumImagesには0枚の画像があります!)。その後、アルバムのuseridでuserのidに、userテーブルに参加しますか。私の問題は、アルバムを1つだけ取得するのではなく、albumsImagesの各画像の結果を取得することです。1つだけが必要です。ここで何が間違っているのでしょうか。
public IQueryable<Album> Get()
{
return (from a in context.Albums
join i in _imageRepository.Get() on a.Id equals i.AlbumId into albumImages
from cover in albumImages.DefaultIfEmpty()
orderby cover.Cover descending, cover.Id ascending
select new Album()
{
Id = a.Id,
UserId = a.UserId,
Name = a.Name,
Created = a.Created,
LastEdit = a.LastEdit,
Description = a.Description,
Views = a.Views,
Location = a.Location,
Photoshoot = a.Photoshoot,
Cover = cover,
});
}
var albums = (from a in AlbumRepository.Get()
join u in UserRepository.Get() on a.UserId equals u.Id
orderby a.Id descending
select new AlbumDisplayModel()
{
Album = a,
User = u
}).ToList();
テスト:
return (from i in _imageRepository.Get()
join album in context.Albums on i.AlbumId equals album.Id into albums
from a in albums.DefaultIfEmpty()
select new Album()
{
Id = a.Id,
UserId = a.UserId,
Name = a.Name,
Created = a.Created,
LastEdit = a.LastEdit,
Description = a.Description,
Views = a.Views,
Location = a.Location,
Photoshoot = a.Photoshoot,
Cover = i,
});