문제

I'm not that familiar with LINQ. I need this query converted into a LINQ statement for use inside my C# project.

Thanks

SELECT Galleries.GalleryTitle, Media.*
FROM Galleries 
INNER JOIN Media ON Galleries.GalleryID = Media.GalleryID
WHERE (Galleries.GalleryID = 100)
도움이 되었습니까?

해결책

var query = from g in db.Galleries
            join m in db.Media on g.GalleryID equals m.GalleryID into gm
            where g.GalleryID == 100
            select new { g.GalleryTitle, Media = gm };

Property Media will contain list of joined media entities. Also if you have navigation property defined in Gallery entity, then:

var gallery = db.Galleries.Include("Media")
                .FirstOrDefault(g => g.GalleryID == 100);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top