Linq:加入共享一个列名称(具有不同数据)的 2 个表
Linq: Join 2 tables that share one column name (with different data)
在 Whosebug 上有几个关于这个主题的问题,但我找不到问题的答案。
我已尝试将 table 费用与 table 信用一起加入。我的问题是我想在加入后访问 'label' 属性(它存在于两个 table 上)。这显然不再可能了,因为它们在加入期间是 'merged'。 我必须声明,尽管属性 'label' 共享相同的名称,但它们不包含相同的信息。
为了解决这个问题,我尝试使用 'let' 关键字,但不幸的是智能感知无法识别我的 'costLabel' 变量(最后一行)。
var query = from cost in COSTS
let costLabel = cost.Label
join credit in CREDITS
on cost.IdCredit equals credit.IdCredit into joined
from j in joined.DefaultIfEmpty()
select new SearchCredit
{
CreditLabel = j.Label,
CostLabel = costLabel
};
使用这个
var query = from cost in COSTS
join credit in CREDITS
on cost.IdCredit equals credit.IdCredit into joined
from j in joined.DefaultIfEmpty()
select new SearchCredit
{
CreditLabel = j.Label,
CostLabel = cost.Label
};
在 Whosebug 上有几个关于这个主题的问题,但我找不到问题的答案。
我已尝试将 table 费用与 table 信用一起加入。我的问题是我想在加入后访问 'label' 属性(它存在于两个 table 上)。这显然不再可能了,因为它们在加入期间是 'merged'。 我必须声明,尽管属性 'label' 共享相同的名称,但它们不包含相同的信息。
为了解决这个问题,我尝试使用 'let' 关键字,但不幸的是智能感知无法识别我的 'costLabel' 变量(最后一行)。
var query = from cost in COSTS
let costLabel = cost.Label
join credit in CREDITS
on cost.IdCredit equals credit.IdCredit into joined
from j in joined.DefaultIfEmpty()
select new SearchCredit
{
CreditLabel = j.Label,
CostLabel = costLabel
};
使用这个
var query = from cost in COSTS
join credit in CREDITS
on cost.IdCredit equals credit.IdCredit into joined
from j in joined.DefaultIfEmpty()
select new SearchCredit
{
CreditLabel = j.Label,
CostLabel = cost.Label
};