0

I have two tables Artist table(PK: ArtistID), Movie Table(PK:MovieID) and a junction table ArtistMovie.
How can I display some columns from both tables Artist and Movie in a datagrid using Linq2Entities:

RentalEntities db = new RentalEntities();

Below is my query:

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
ArchieTiger
  • 2,083
  • 8
  • 30
  • 45

1 Answers1

1

I would think this should work:

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
};
Grandizer
  • 2,819
  • 4
  • 46
  • 75
  • This will work, just a note though, you don't need the names of the fields in the select as you're projecting into an anonymous types and the field names you have specified are exactly the same as the names of the fields you are selecting – Mathew Thompson Apr 13 '12 at 14:25