ToList and Querying multiple entities

I have the following code for the SelectedIndexChanged event of a drop down list. This works fine as it is but this entity has a relationship to another entity (Genre). if i change the select statement to { m, m.Genre.MovieGenre }).ToList(); it doesnt work as contains anonomyous types.

How would i go about doing this. Still trying to get to grips with all this so apologise if i havent explained very well!

//get dvd
using (var context = new dvd3Entities())
	int id = Convert.ToInt32(ddlDvd.SelectedValue);
	List<Movie> movies = (from m in context.Movies
	    where m.Id == id
   	    select m).ToList();

	if (movies.Count() > 0)
	    Movie movie = movies[0];
	    txtTitle.Text = movie.Title;
	    txtYear.Text = movie.Year;


thanks :slight_smile:

You do not need to do that. Leave it as is and just use DataLoadOptions

DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith<Movies>(o o=> o.Genre);

context.LoadOptions = dlo;

Then do your query. It will do the join, and u can bind to it as per normal.

Either that or you will have to create a custom class with all the custom fields in and load to that. Or u have ot use anonymous types