Linq to Entities Inner加入datagrid

时间:2012-04-13 08:07:49

标签: c# sql linq-to-entities wpfdatagrid multiple-tables

我有两张表艺术家表(PK:ArtistID),电影表(PK:MovieID)和一张表格ArtistMovie。
如何使用Linq2Entities:

在数据网格中显示两个表Artist和Movie中的列

RentalEntities db = new RentalEntities();

以下是我的询问:

SELECT Movie.MovieName,
       Movie.Year, 
       Artist.ArtistName,
       Artist.Age 
       FROM Artist INNER JOIN ArtistMovie ON Artist.ArtistID = ArtistMovie.ArtistID
                   INNER JOIN Movie ON ArtistMovie.MovieID = Movie.MovieID

1 个答案:

答案 0 :(得分:1)

我认为这应该有效:

from a in db.Artist
join am in db.ArtistMovie on a.ArtistID equals am.ArtistID
join m in db.Movie on am.MovieID equals m.MovieID
select new {
    MovieName = m.MovieName,
    Year = m.Year,
    ArtistName = a.ArtistName,
    Age = a.Age
};