我对LINQ并不熟悉。我需要将此查询转换为LINQ语句,以便在我的C#项目中使用。
由于
SELECT Galleries.GalleryTitle, Media.*
FROM Galleries
INNER JOIN Media ON Galleries.GalleryID = Media.GalleryID
WHERE (Galleries.GalleryID = 100)
答案 0 :(得分: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);