I'm using Entity framework and I have a Repository class that does all the data fetching with a dbContext
object.
Currently there's a method called
public MovieDetails FindSingle(int? id)
{
using (MovieContext dbContext = new MovieContext())
{
var newMovieDetails = dbContext.Movies.FirstOrDefault(x => x.MovieID == id);
if (newMovieDetails == null)
{
throw new Exception();
}
var MappedDetails = new MovieDetails
{
MovieID = newMovieDetails.MovieID,
MovieName = newMovieDetails.MovieName
};
return MappedDetails;
}
}
Currently when the program finds a match in database, it gets converted to a Data Object Transfer-object
When I try to search for a movie that does not exist in database, I get an error. Is there a way I could return a type that says that no such row exists in database? Or should I just return an empty object?