20070209

LINQ - Explicit Query

This is for Justice Gray.

I had to watch ALL the movies. Took 5 hours, and DAMN it was worth it! I actually just wanted to see the credits!



 [Test]


        public void ShouldFindUsingLINQ()


        {


            List<Movie> movies = CreateMovie();


 


            var results = from m in movies


                          from a in m.Actors


                          where a.FirstName == "Hannah" &&


                              a.LastName == "Harper"


                            select new {a.FirstName, m.Title, a.ScreenName};


 


            foreach (var result in results)


            {


                Console.Out.WriteLine("{0} is an actress in the movie {1} and her screen name is {2}",


                                  result.FirstName, result.Title, result.ScreenName);


            }


 


            /*Output


            *Hannah is an actress in the movie 8 Inches and her screen name is Enduro Girl


            *Hannah is an actress in the movie Assploitations 4 and her screen name is Hanna


            */


        }


 


        private static List<Movie> CreateMovie()


        {


            List<Movie> movies = new List<Movie>();


            movies.Add(CreateMovie("8 Inches", "Some chick that wished she swallowed 8 inches of wang ",


                                  CreateActor("Hannah", "Harper", "Enduro Girl")));


            movies.Add(CreateMovie("Internal Cumbustion 10", string.Empty,


                                      CreateActor("Evelyne ", "Foxy", "Evelyne"),


                                      CreateActor("Jenna", "Haze  ", "Jenna"),


                                      CreateActor("Isabel", "Ice", "Isabel"),


                                      CreateActor("Kid", "Jamaica", "Jamaica"),


                                      CreateActor("Virginee ", string.Empty, "Virginee")));


            movies.Add(CreateMovie("Assploitations 4", string.Empty,


                                      CreateActor("Hannah", "Harper", "Hanna"),


                                      CreateActor("Shayna", "Knight      ", "Shayna"),


                                      CreateActor("Lucy", "Lee", "Lucy"),


                                      CreateActor("Lauren", "Phoenix  ", "Lauren"),


                                      CreateActor("Aurora ", "Snow", "Aurora")));


            return movies;


        }


 


        private static Actor CreateActor(string firstName, string lastName, string screenName)


        {


            Actor actor = new Actor();


            actor.FirstName = firstName;


            actor.LastName = lastName;


            actor.ScreenName = screenName;


 


            return actor;


        }


 


        private static Movie CreateMovie(string title, string description, params Actor[] actors)


        {


            Movie movie = new Movie();


            movie.Title = title;


            movie.Description = description;


            movie.Actors = AddActors(actors);


 


            return movie;


        }


1 comments:

Justice~! said...

*FANTASTIC*. I also appreciate you making the supreme sacrifice of watching 5 hours of hardcore Hanna Harper porn - you definitely took one for the team! I recommend expanding this in to a presentation and taking it on the road!