// GET: Home public ActionResult Index() { //LINQ выражение + передача в представление TestMToMEntities context = new TestMToMEntities(); var list = from students in context.Students from courses in students.Courses select new TestModel() { StudentName = students.Student, CourseName = courses.Course }; return(View(list)); }
public ActionResult Index() { TestMToMEntities context = new TestMToMEntities(); var listOutCSharp = context.Courses .SelectMany( course => course.Students /*, * (course, student) => new { * StudentName = student.Student, * CourseName = course.Course * }*/).ToList(); return(View(listOutCSharp)); }
static void Main(string[] args) { //запрос многие ко многим LINQ TestMToMEntities context = new TestMToMEntities(); var list = from students in context.Students from courses in students.Courses select new { StudentName = students.Student, CourseName = courses.Course }; foreach (var item in list) { Console.WriteLine("Студент = {0} Курс = {1}", item.StudentName, item.CourseName); } Console.ReadKey(); }