static void Main() { var context = new MoviesContext(); JavaScriptSerializer js = new JavaScriptSerializer(); var adultMovies = context.Movies .OrderBy(m => m.Title) .ThenBy(m => m.Ratings.Select(r => r.Stars).Count()) .Where(m => m.AgeRestriction == AgeRestriction.Adult) .Select(m => new { title = m.Title, ratingsGiven = m.Ratings.Select(r => r.Stars).Count() }); var json = js.Serialize(adultMovies); File.WriteAllText(@"..\..\adult-movies.json", json); }
static void Main(string[] args) { var context = new MoviesContext(); JavaScriptSerializer js = new JavaScriptSerializer(); var top10FavoriteMovies = context.Movies .Where(m => m.AgeRestriction == AgeRestriction.Teen) .OrderByDescending(m => m.Users.Count()) .ThenBy(m => m.Title) .Select(m => new { isbn = m.Isbn, title = m.Title, favouritedBy = m.Users.Select(u => u.Username) }) .Take(10); var json = js.Serialize(top10FavoriteMovies); File.WriteAllText(@"..\..\top-10-favourite-movies.json", json); }
static void Main() { var context = new MoviesContext(); JavaScriptSerializer js = new JavaScriptSerializer(); var ratedMoviesByJmeyery = context.Users .Where(u => u.Username == "jmeyery") .Select(u => new { username = u.Username, ratedMovies = u.Ratings.Select(r => new { title = r.Movie.Title, userRating = r.Stars, averageRating = r.Movie.Ratings.Average(mr => mr.Stars) }) }); var json = js.Serialize(ratedMoviesByJmeyery); File.WriteAllText(@"..\..\rated-movies-by-jmeyery.json", json); }
static void Main() { var context = new MoviesContext(); context.Countries.Count(); }