April 28, 2024

LINQ and a Multi-column Join Problem

What causes the following LINQ query to generate a "The type of one of the expressions in the join clause is incorrect.  Type inference failed in the call to ‘Join’" error?

from doc in BvdDoc
join job in BvdJob on doc.BvdDocID equals job.BvdDocID
join iter in BvdIteration on job.BvdJobID equals iter.BvdJobID
join mbr in VMember on doc.Adloc.Substring(0, 2) equals mbr.MbrID
join ttl in VTitleCode on new { mbr.WrkStn, iter.TitleCode } equals new { ttl.PayPlan, ttl.TitleCode }
select new {
    doc.BvdDocID,
    doc.Adloc,
    job.BvdJobID,
    iter.BvdIterationID,
    iter.TitleCode,
    mbr.MbrID
}

Answer: The anonymous types created on the join to the title code view must have matching property names, as in:

join ttl in VTitleCode on new { Workstation = mbr.WrkStn, iter.TitleCode } equals new { Workstation = ttl.PayPlan, ttl.TitleCode }

Leave a Reply