How do I convert this SQL inner join query into LI

2019-08-24 01:47发布

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)

1条回答
趁早两清
2楼-- · 2019-08-24 02:22
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);
查看更多
登录 后发表回答