Ejemplo n.º 1
0
        static void RunExample()
        {
            using (var context = new EFRecipesEntities())
            {
                var blogpost = new BlogPosting {
                    Title = "ASP.NET MVC", Author = "Steven Grace", Post = "What's New", Comments = "50"
                };
                var story = new Story {
                    Title = "Time in a Bottle", Author = "Emily Jones", Plot = "Murder on the high seas"
                };
                var ed = new EducationalVideo {
                    Instructor = "Joseph Robins", ResourcePath = "\\videos\asp.wmv", Title = "ASP.NET Examples"
                };
                var movie = new RecreationalVideo {
                    Title = "Archie's Place", Rating = 1, ResourcePath = "\\videos\archie.wmv"
                };
                context.Media.AddObject(blogpost);
                context.Media.AddObject(story);
                context.Media.AddObject(ed);
                context.Media.AddObject(movie);
                context.SaveChanges();
            }

            using (var context = new EFRecipesEntities())
            {
                Console.WriteLine("All of the media...");
                foreach (var m in context.Media)
                {
                    Console.WriteLine();
                    if (m is BlogPosting)
                    {
                        var post = (BlogPosting)m;
                        Console.WriteLine("Blog Posting");
                        Console.WriteLine("Title: {0}, Author: {1}, Post: {2}", post.Title, post.Author, post.Post);
                    }
                    else if (m is Story)
                    {
                        var story = (Story)m;
                        Console.WriteLine("Story");
                        Console.WriteLine("Title: {0}, Author: {1}, Plot: {2}", story.Title, story.Author, story.Plot);
                    }
                    else if (m is EducationalVideo)
                    {
                        var edvideo = (EducationalVideo)m;
                        Console.WriteLine("Educational Video");
                        Console.WriteLine("Title: {0}, Instructor: {1}", edvideo.Title, edvideo.Instructor);
                    }
                    else if (m is RecreationalVideo)
                    {
                        var video = (RecreationalVideo)m;
                        Console.WriteLine("Recreational Video");
                        Console.WriteLine("Title: {0}, Rating: {1}", video.Title, video.Rating.ToString());
                    }
                }
            }

            Console.WriteLine("Press <enter> to continue...");
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a new BlogPosting object.
        /// </summary>
        /// <param name="mediaId">Initial value of the MediaId property.</param>
        /// <param name="title">Initial value of the Title property.</param>
        /// <param name="author">Initial value of the Author property.</param>
        /// <param name="post">Initial value of the Post property.</param>
        public static BlogPosting CreateBlogPosting(global::System.Int32 mediaId, global::System.String title, global::System.String author, global::System.String post)
        {
            BlogPosting blogPosting = new BlogPosting();

            blogPosting.MediaId = mediaId;

            blogPosting.Title = title;

            blogPosting.Author = author;

            blogPosting.Post = post;

            return(blogPosting);
        }