Question

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)
Était-ce utile?

La solution

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);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top