【发布时间】:2016-01-27 17:18:31
【问题描述】:
我尝试将单行中的多行与 2 个表连接起来,其中一个表有一个外键
我有这张桌子:
台式打印机:
PrinterID Name Description
--------------------------------
1 Printer1 Description1
2 Printer2 Description2
表格分辨率:
ResolutionID Measure PrinterId
--------------------------------
1 123 1
2 234 1
3 345 2
4 456 2
我在 GridView 中需要这个:
PrinterID Name Description Resolution
------------------------------------------------------------------------
1 Printer1 Description1 123, 234
2 Printer2 Description2 345, 456
我有这个代码,但我卡住了
var Printer = from tPrinter in Context.Printer
join tResolution in Context.Resolution on tPrinter.PrinterId equals tResolution.PrinterId into collection2
from subcase2 in collection2.DefaultIfEmpty()
where tPrinter.DisableDate == null
select new
{
tPrinterPrinterId = tPrinter.PrinterId,
tPrinterName = tPrinter.Name,
tPrinterDescription = tPrinter.Description,
tCountryName = tPrinter.City1.State.Country.Name,
tStateName = tPrinter.City1.State.Name,
tCityName = tPrinter.City1.Name
};
return Printer
【问题讨论】:
-
不应该是
tprinter.PrinterId吗?在线:on Printer.PrinterId equals tRe... -
是的,你是对的,很抱歉这个错误
-
现在可以用了吗?
-
你使用EntityFramework吗?以及如何打开上下文?
-
是的,连接不是问题,实体适用于所有其余查询