我正在學習使用LINQ,EF等。我有2個自動生成的edmx類course
和student
。我寫了一個代碼來訪問course id
和course name
。有了這些數據,我也想分別獲取參加課程的students names
的數據。以下是我的代碼。訪問一對多關係數據
testEntities1 t = new testEntities1();
var u = (from g in t.courses
select new
{
g.C_Id,
g.C_Name,
dd = g.student.Select(r=>r.S_Name)
}).ToList();
現在如何使用/我從中選擇了其中包含有誰報名參加課程的所有學生的名字屬性dd
獲取數據。我可以將數據存入變量u
。我只是不知道如何處理並從dd
獲取數據。請幫忙。以下是獲取course id
和course name
的數據的行。我如何獲得學生姓名的數據。所有的
List<course> ui = u.Select(d => new course() { C_Name = d.C_Name, C_Id = d.C_Id }).ToList();
你可以發佈課程類型嗎? – 2014-12-09 12:46:30