2011-03-19 59 views
1

我有4個表格,需要編寫一個linq查詢來從所有表格中提取信息!在linqToSql中加入4個表格

這裏是表結構:

打印機:

  • printerID
  • PrinterName的

模板:

  • TemplateID
  • TemplateCategoryID
  • TEMPLATENAME

TemplateCategory:

  • TemplatecategoryID
  • TemplatecategoryName

數據:

  • 數據ID
  • PrinterID
  • TemplateID
  • CreatedDate
  • IsProcessedDate

我想要的信息是:

PrinterName的,TemplateCategory,TEMPLATENAME,數據CreatedDate,數據IsprocessedDate。

我都是新來的linq,無法識別解決這個問題的方法。如果有人對此有任何評論,那麼可以給予很多評論。

非常感謝,芬蘭人。

+0

設置在DB的主/外鍵時,將不再需要編寫一個加入聲明 – Guillaume86 2011-03-19 17:09:27

回答

2

一些假設,添加上下文引用:

from d in Data 
join t in Tempalte on d.TemplateID equals t.TempateID 
join tc in TemplateCategory on t.TemplateCategoryID equals tc.TemplateCategoryID 
join p in Printer on d.PrinterID equals p.PrinterID 
select new 
{ 
    p.PrinterName, 
    tc.TemplatecategoryName, 
    t.TemplateName, 
    d.CreatedDate, 
    d.IsProcessedDate 
}