Reputation: 12475
I have this linq query:
var segreterie = from s in db.USR_Utenti join h in db.USR_Accounts
on new {s.ID, settings.GruppoSegreteria}
equals new {h.USR_UtentiReference,h.ID_Gruppo} select s;
that has this problem:
The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.
how can i do to solve it?
Upvotes: 1
Views: 358
Reputation: 945
On a similar note, if you are doing a join on a field which is nullable (for e.g., int and int?) you may have to do something like (where Field2 is int? in Table1 and int in Table2):
from l in Table1
join l2 in Table2
on new { l.Field1, Field2 = (l.Field2.Value == null ? -1 : l.Field2.Value) } equals new { l2.Field1, Field2 = l2.Field2 }
Upvotes: 0
Reputation: 1503669
The two types should be the same - which means they'll need the same property names as you're using anonymous types. Try this:
var segreterie = from s in db.USR_Utenti join h in db.USR_Accounts
on new {s.ID, Groups = settings.GruppoSegreteria}
equals new {ID = h.USR_UtentiReference, Groups = h.ID_Gruppo}
select s;
That's assuming that s.ID
and h.USR_UtentiReference
have the same type, and settings.GruppoSegreteria
and h.ID_Gruppo
do likewise.
Upvotes: 6