开发者

Joining 4 tables in linqToSql

开发者 https://www.devze.com 2023-02-18 01:06 出处:网络
I have 4 tables and need to write a linq query to pull information from all tables! Here is the table structure:

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

精彩评论

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

关注公众号