0

我对LINQ不太熟悉。我需要将此查询转换为 LINQ 语句,以便在我的 C# 项目中使用。

谢谢

SELECT Galleries.GalleryTitle, Media.*
FROM Galleries 
INNER JOIN Media ON Galleries.GalleryID = Media.GalleryID
WHERE (Galleries.GalleryID = 100)
4

1 回答 1

4
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 };

属性Media将包含加入的媒体实体列表。此外,如果您在 Gallery 实体中定义了导航属性,则:

var gallery = db.Galleries.Include("Media")
                .FirstOrDefault(g => g.GalleryID == 100);
于 2013-01-02T19:57:19.347 回答