mauroneto
mauroneto

Reputation: 98

LINQ Join with same Name on different tables

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
}

Upvotes: 1

Views: 508

Answers (1)

Rahul Singh
Rahul Singh

Reputation: 21795

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.

Upvotes: 1

Related Questions