1

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?

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.