我对LINQ不太熟悉。我需要将此查询转换为 LINQ 语句,以便在我的 C# 项目中使用。
谢谢
SELECT Galleries.GalleryTitle, Media.*
FROM Galleries
INNER JOIN Media ON Galleries.GalleryID = Media.GalleryID
WHERE (Galleries.GalleryID = 100)
我对LINQ不太熟悉。我需要将此查询转换为 LINQ 语句,以便在我的 C# 项目中使用。
谢谢
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 };
属性Media
将包含加入的媒体实体列表。此外,如果您在 Gallery 实体中定义了导航属性,则:
var gallery = db.Galleries.Include("Media")
.FirstOrDefault(g => g.GalleryID == 100);