LINQ加入对不同的表相同的名称 [英] LINQ Join with same Name on different tables
本文介绍了LINQ加入对不同的表相同的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在加入2表时遇到了麻烦,这个问题就行
加入革命制度党在ProductPricingSet新{o.BusinessUnitId.Id,opr.ProductNameId.Id}等于新{pri.BusinessUnitId.Id,pri.ProductId.Id`}
即时得到获得匿名类型不能有多个属性具有相同的名称
我试图重新命名它做没有运气,还有什么其他的选择有没有?
从o在OrderSet
加入OPR在OrderProductSet上o.Id等于opr.OrderId.Id
加入革命制度党在ProductPricingSet新{o.BusinessUnitId.Id,opr.ProductNameId.Id}等于新{pri.BusinessUnitId.Id,pri.ProductId.Id}
其中,o.Name.Equals(OE-000004)
选择新{
o.name,
opr.ProductName,
opr.Quantity,
pri.SlipDiscount,
pri.FinalPrice
}
解决方案
试试这个: -
从o在OrderSet
加入OPR在OrderProductSet上o.Id等于opr.OrderId.Id
加入革命制度党在ProductPricingSet上
新{BusinessUnitId = o.BusinessUnitId.Id,ProductNameId = opr.ProductNameId.Id}
等于新{BusinessUnitId = pri.BusinessUnitId.Id,ProductNameId = pri.ProductId.Id}
其中,o.Name.Equals(OE-000004)
选择新
{
o.name,
opr.ProductName,
opr.Quantity,
pri.SlipDiscount,
pri.FinalPrice
}
在匿名
你使用会产生相同的名称,这样的冲突发生,你需要分配单独的名称类型。
I'm having trouble when joining 2 tables, The issue is on the line
join pri in ProductPricingSet on new {o.BusinessUnitId.Id, opr.ProductNameId.Id} equals new {pri.BusinessUnitId.Id, pri.ProductId.Id`}
Im getting "getting "An anonymous type cannot have multiple properties with the same name"
i've tried to rename it do no luck, what other option is there?
from o in OrderSet
join opr in OrderProductSet on o.Id equals opr.OrderId.Id
join pri in ProductPricingSet on new {o.BusinessUnitId.Id, opr.ProductNameId.Id} equals new {pri.BusinessUnitId.Id, pri.ProductId.Id}
where o.Name.Equals("OE-000004")
select new {
o.name,
opr.ProductName,
opr.Quantity,
pri.SlipDiscount,
pri.FinalPrice
}
解决方案
Try this:-
from o in OrderSet
join opr in OrderProductSet on o.Id equals opr.OrderId.Id
join pri in ProductPricingSet on
new { BusinessUnitId = o.BusinessUnitId.Id, ProductNameId = opr.ProductNameId.Id}
equals new { BusinessUnitId = pri.BusinessUnitId.Id, ProductNameId = pri.ProductId.Id}
where o.Name.Equals("OE-000004")
select new
{
o.name,
opr.ProductName,
opr.Quantity,
pri.SlipDiscount,
pri.FinalPrice
}
The anonymous
type you are using will generate the same name so conflict is happening, you need to assign separate name.
这篇关于LINQ加入对不同的表相同的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文