EntityFramework 学习 一 Stored Procedure
CREATE PROCEDURE [dbo].[GetCoursesByStudentId] -- Add the parameters for the stored procedure here @StudentId int = null AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here select c.courseid, c.coursename,c.Location, c.TeacherId from student s left outer join studentcourse sc on sc.studentid = s.studentid left outer join course c on c.courseid = sc.courseid where s.studentid = @StudentId END
using (var context = new SchoolDBEntities()) { var courses = context.GetCoursesByStudentId(1); foreach (Course cs in courses) Console.WriteLine(cs.CourseName); }