开发者

Joining 4 tables in linqToSql

I have 4 tables and need to write a linq query to pull information from all tables!

Here is the table structure:

Printer:

  • printerID
  • PrinterName

Template:

  • TemplateID
  • TemplateCategoryID
  • TemplateName

TemplateCategory:

  • TemplatecategoryID
  • TemplatecategoryName

Data:

  • DataID
  • PrinterID
  • TemplateID
  • CreatedDate
  • IsProcessedDate

The information I want is:

PrinterName, TemplateCategory, TemplateName, Data-CreatedDate, Data-Isprocessed开发者_如何转开发Date.

I'm all new to linq and cannot recognize the way to solve this. Much appriciated if anyone has any comment on this.

Thanks alot, Finn.


with some assumptions, add your context reference:

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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜