我有两张桌子: EndToEnd和PartPort。我希望从PartPortA和PartportB中的同一行获取EndToEnd数据,并使用它们查询Partport,并从Partport获取相应的PartGid,这可能位于Partport表的任何行上。到目前为止,我能够做到这一点,但我必须做两个不同的LINQ调用,但我想把它减少到一个。这是我的代码:
// this demonstrates how to join two tables, however only works for one AssetportGid at a time
var part_portGid_a_results = (from icp in entities.EndToEnd
where icp.IntertPortGidA != null &&
icp.IntertPortGidB != null
join ica in entities.PartPort
on icp.PartPortA equals ica.PortGid
select new { icp.PartPortA, ica.PartGid, }).ToList();
var part_portGid_b_results = (from icp in entities.EndToEnd
where icp.IntertPortGidA != null &&
icp.IntertPortGidB != null
join ica in entities.PartPort
on icp.PartPortB equals ica.PortGid
select new { icp.PartPortA, ica.PartGid, }).ToList();
return Json(part_portGid_a_results, JsonRequestBehavior.AllowGet);我想做的是,我已经试过了,但有一个错误是:
var part_portGid_a_results = (from icp in entities.EndToEnd
where icp.IntertPortGidA != null &&
icp.IntertPortGidB != null
join ica in entities.PartPort
on icp.PartPortA && icp.PartPortB equals ica.PortGid
select new { icp.PartPortA, ica.PartGid, }).ToList();我得到的错误是:
Guid? EndToEnd.PartPortB
Error:
Operator '&&' cannot be applied to operands of type 'System.Guid' and 'System.Guid?'发布于 2016-08-23 19:29:07
你不用用连接。如果您想加入一个“复杂”比较,只需制作一个笛卡尔乘积(from ... from)并通过一个where子句链接行。
var part_portGid_results = (from icp in entities.EndToEnd
where icp.IntertPortGidA != null &&
icp.IntertPortGidB != null
from ica in entities.PartPort
where icp.PartPortA == ica.PortGid
|| icp.PartPortB == ica.PortGid
select new { icp.PartPortA, ica.PartGid, }).ToList();https://stackoverflow.com/questions/39108995
复制相似问题