我有这个linq查询:
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;
有这个问题:
The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.
我该怎么做才能解决它?
答案 0 :(得分:6)
这两种类型应该是相同的 - 这意味着它们需要与您使用匿名类型相同的属性名称。试试这个:
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;
假设s.ID
和h.USR_UtentiReference
具有相同的类型,而settings.GruppoSegreteria
和h.ID_Gruppo
也是如此。
答案 1 :(得分:0)
在类似的说明中,如果你在一个可以为空的字段上进行连接(例如,int和int?),你可能需要做类似的事情(其中Field2是表1中的int?和表2中的int):
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 }