2011-03-19 62 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 
}