2

我在以下 linq 查询(第 2 行)中收到以下错误,我不明白如何更正它。

join 子句中的表达式之一的类型不正确。对“加入”的调用中的类型推断失败。

equals 表达式中的所有 2 个变量都是 (string) 所以我不确定为什么会导致这个错误。有没有人有什么建议?

var studentlist = from t1 in  Extern
                  join t2 in EMPstatus //m receiving the error here 
                  on new { t1.id} equals new { id= t2.id }
                  join t3 in StatusofEmp
                  on new { t2.Sta_ID } equals new {Sta_ID = t3.Sta_ID }
                  where t3.Status = "INAKTIV" 
                  select new { t1.Name };
4

2 回答 2

0

使用时无需创建新的匿名对象join

尝试这样的事情:

var studentlist = 
    from t1 in  Extern
    join t2 in EMPstatus
    on t1.id equals t2.id
    join t3 in StatusofEmp
    on t2.Sta_ID equals t3.Sta_ID
    where t3.Status = "INAKTIV" 
    select new { t1.Name };
于 2013-10-07T14:35:24.513 回答
0

根据您的描述,我猜您的 id 列之一可能是可空的,而另一个不可为空。检查哪一个是可空的,假设 t1 id 可空且 t2 id 不可空,然后在连接条件中设置波纹管语法id=(t1.id??0) equals t2.id

希望以上语法有助于解决您的问题。

var studentlist = from t1 in  Extern
                  join t2 in EMPstatus //m receiving the error here 
                  on  id=(t1.id??0) equals  id= t2.id 
                  join t3 in StatusofEmp
                  on new { t2.Sta_ID } equals new {Sta_ID = t3.Sta_ID }
                  where t3.Status = "INAKTIV" 
                  select new { t1.Name };
于 2013-10-07T14:58:49.600 回答