2013-01-20 62 views
0

我'初學者檢索數據和有三個表(SQL CE 3.5)所示: 過程:(PK)CourseCode,CourseName 類:(PK)ClassCode,FieldCode,類名 ClsCrs (PK)ClassCode,(PK)CourseCode從多個表中與LINQ LINQ

我想轉換或此查詢重寫LINQ和分配結果的組合框的數據源:

`SELECT CourseName FROM class, clscrs, course WHERE 
ClassTitel = @ClassTitel and class.classcode = clscrs.classcode and 
clscrs.coursecode = course.coursecode` 

我怎麼能做到這一點?

謝謝

+0

? LINQ to SQL?實體框架? NHibernate的?還有別的嗎? – svick

+0

yes.linq到sql –

回答

0

它不清楚哪個表ClassTitel字段屬於(假設類表)。還與EF或LINQ生成的替換集名稱爲SQL

var query = from cl in db.class 
      join cc in db.clscrs on cl.classcode equals cc.classcode 
      join cs in db.course on cc.coursecode equals cs.coursecode 
      where cl.ClassTitel == "value" 
      select cl.CourseName; 

comboBox1.DataSource = query.ToList(); 
1

你可以試試這個

var query = (from c in db.class 
      from v in db.clscrs 
      from n in db.course 
      where c.ClassTitel=="yourinput" 
       && c.classcode = v.classcode 
       && v.coursecode = n.coursecode 
      select n.CourseName).ToList(); 
您使用哪種LINQ提供