예제 #1
0
        //filtrare film
        public static void FilterMovieByGenere()
        {
            CinemaDataContext db = new CinemaDataContext(connectionString);

            foreach (var movie in db.Movies)
            {
                Console.WriteLine("{0} - {1}, {2}", movie.ID, movie.Title, movie.Genere);
            }
            Console.WriteLine("Che genere ti interessa?");
            string genere = Console.ReadLine();

            IQueryable <Movy> moviesFiltered =
                from m in db.Movies
                where m.Genere == genere
                select m;

            foreach (var movie in moviesFiltered)
            {
                Console.WriteLine("{0} - {1}, {2}", movie.ID, movie.Title, movie.Genere);
            }
        }
예제 #2
0
        //Inserire record
        public static void InsertMovie()
        {
            CinemaDataContext db = new CinemaDataContext(connectionString);

            SelectMovies();

            var movieToInsert = new Movy();

            movieToInsert.Title  = "Lalaland";
            movieToInsert.Genere = "Musical";
            movieToInsert.Durata = 120;

            db.Movies.InsertOnSubmit(movieToInsert);

            try
            {
                db.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            SelectMovies(); //se lo faccio prima di submit changes non vedo il nuovo film

            var DeleteMovie = db.Movies.SingleOrDefault(m => m.ID == 9);

            if (DeleteMovie != null)
            {
                db.Movies.DeleteOnSubmit(DeleteMovie);
            }
            try
            {
                db.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            SelectMovies();
        }