Paul Rusu
Paul Rusu

Reputation: 23

the same old "the type of one of the expressions in the join clause is incorrect"

I know there are many questions about this. I have read them and I have made the same name and type for the anonymous types properties. Still I get the error in the title.

Code is:

var v = (from o in dataContext.pp_orders.Where(p => p.ID > lastOrderID).OrderBy(p => p.DueDate)
                 join part in dataContext.pp_parts on o.ProductID equals part.ProductID
                 join op in dataContext.pp_operations on new { ID2 = part.ID } equals new { ID2 = (int)op.PartID }
                 select (x => new JobModel { o = o, op = op }));

The error is at the second join.

[UPDATE]

It seems the join equals are correct. This query works (no error):

var v = (from o in dataContext.pp_orders.Where(p => p.ID > lastOrderID).OrderBy(p => p.DueDate)
                 join part in dataContext.pp_parts on o.ProductID equals part.ProductID
                 join op in dataContext.pp_operations on part.ID equals (int)op.PartID
                 select op);

The problem is with the select clause. I don't understand why it gives the error in the title at that select clause.

select (x => new JobModel { o = o, op = op })

Upvotes: 0

Views: 47

Answers (1)

D Stanley
D Stanley

Reputation: 152521

You're mixing query syntax and method syntax. Method syntax uses lamdbas to project data, while query syntax uses more natural sql-like syntax:

change your select to:

select new JobModel { o = o, op = op }

Upvotes: 1

Related Questions