I'm trying to count all instances of Movie_Instance that contain a foreign key of a movie in the Movie table.
Here is my code:
var query = entities.Movie.Join(entities.Movie_Instance,
movie2 => movie.ID_Movie,
movie_instance => movie_instance.FK_ID_Movie,
(movie2, movie_instance) => new { Movi = movie, Movie_Instanc = movie_instance })
.Where(data => data.Movi.ID_Movie == data .Movie_Instanc.FK_ID_Movie
&& data .Movi.ID_Movie == movie.ID_Movie)
.SelectMany(e => entities.Movie_Instance).Count();
What I get when I run this is an error:
System.NotSupportedException: 'Unable to create a constant value of type 'DBFilmy.Movie'. Only primitive types or enumeration types are supported in this context
[EDIT]
]1
Movie_instance contains instances of Movie. It's connected using foreign key (FK_ID_Movie -> ID_Movie) I have multiple instances of Movie and each of them is stored in Movie_Instance. I'd like to count how many instances of movie I have (movie is an object of Movie type)
Here is where I get movie:
var x = entities.Movie
.Where(c => c.Title.Contains(_title)
&& c.Director.Contains(_director)
&& c.Category.Contains(_category));
foreach (var movie in x)
{
...
}