我可以这样查询吗?
var result = from us20 in Us20Repository.GetAll()
join pj01 in Pj01Repository.GetAll() on new
{
User =
(us20.company == "kodofisi" ?
us20.personalId :
(
us20.company == "coca-cola" ?
(
(from pj02 in Pj02Repository.GetAll()
where
pj02.id == us20.id &&
pj02.personalId == us20.personalId
select new
{
pj02.id
}).First().ToString()
) :
""
)
),
ACTIVE = "X"
} equals new { User = pj01.name, ACTIVE = pj01.active }
select new
{
Name = pj01.id
};
这在加入时不起作用,如何使用select来完成?数据没有来。
相应的查询是否有效:
/*bla bla*/ FROM us20 US20 INNER JOIN pj01 PJ01 ON PJ01.PJID = ( CASE WHEN (US20.company = "kodofisi") THEN US20.personalId WHEN (US20.BKNM = "coca-cola") THEN ( SELECT dataId FROM pj02 WHERE id = US20.id AND personalId = US20.personalId ) END ) AND PJ01.active = "X"
答案 0 :(得分:0)
我不知道这是否是造成问题的原因,但也许您可以尝试在代码段上使用FirstOrDefault()而不是First():
(from pj02 in Pj02Repository.GetAll()
where
pj02.id == us20.id &&
pj02.personalId == us20.personalId
select new
{
pj02.id
}).First().ToString()
这种变化解决了我遇到的类似问题。