Example #1
0
        /*
         * Before executing it, proper information should be on
         * Student, Course and StudentCourse table
         *
         * For Insert, Update and Delete stored proc, please check it out with
         * http://www.entityframeworktutorial.net/EntityFramework5/CRUD-using-stored-procedures.aspx
         */
        public static void ReadDataUsingStoredProcedure()
        {
            Console.WriteLine("*** ReadDataUsingStoredProcedure Starts ***");

            using (var context = new SchoolDBEntities())
            {
                context.Database.Log = Console.Write;
                //get all the courses of student whose id is 1
                var courses = context.GetCoursesByStudentId(5);
                //Set Course entity as return type of GetCoursesByStudentId function
                //Open ModelBrowser -> Function Imports -> Right click on GetCoursesByStudentId and Edit
                //Change Returns a Collection of to Course Entity from Complex Type
                //uncomment following lines
                foreach (Course cs in courses)
                {
                    Console.WriteLine(cs.CourseName);
                }
            }

            Console.WriteLine("*** ReadDataUsingStoredProcedure Ends ***");
        }