I have a post action in my API which creates an order based off some data it retrieves from a view model.
It needs to be able to retrieve all movies from a table of 'movies' that are passed to it via the view model and create an order. The view model passes the action the Ids of the movies it needs to retrieve.
I have a working solution, and when giving the action data like this it works:
{
"movieIds": [34, 35],
"customerId": 21
}
database:
However when I give the action data which contains two or more movies with the same Id, it only ever saves one movie.
{
"movieIds": [34, 34],
"customerId": 21
}
database:
After debugging the code, i found out that it's this linq statement which is causing the problem, it only ever saves one instance of the movie to 'movies'.
movies = _context.Movies.Where(m => newRental.MovieIds.Contains(m.Id)).ToList();
Does anyone know why it does this? and how to construct a linq statement that allows it to save multiple Ids?