LINQ JOIN有多个条件返回错误

本文关键字:条件 返回 错误 JOIN LINQ | 更新日期: 2023-09-27 18:27:56

我浏览了各种问答;A对于这种情况,但我的错误仍然存在。

我有以下内容:

Int32 eid = Convert.ToInt32(this.ddlPrograms.SelectedItem.Value);
var participants =
    from b in _dc.WebProgramParticipants
    join d in _dc.webeventaffiliations
        on new { b.UserID, eid } equals new { d.userid, d.eventid }
    join c in _dc.WebPersonalInfos
        on b.UserID equals c.UserID
    where (b.eventid == eid) select
    new { b.ParticipantID, c.FirstName, c.LastName, c.Email, d.institution };

有问题的联接的类型{b.UserID=int,b.eventid=int?}和等于{d.UserID=int,d.eventid=int}

"联接子句中某个表达式的类型不正确。对"联接"的调用中的类型推理失败。"的错误不会消失。据说第一个join有类型问题,但唯一的问题是b.eventid是一个可以为null的,我认为包含eid变量会起作用,但事实并非如此。

这是怎么回事?

LINQ JOIN有多个条件返回错误

通过以下解决

var participants = from b in _dc.WebProgramParticipants join d in _dc.webeventaffiliations on new { UserID = b.UserID, eventid = eid } equals new { UserID = d.userid, eventid = d.eventid } join c in _dc.WebPersonalInfos on b.UserID equals c.UserID where (b.eventid == eid) select new { b.ParticipantID, c.FirstName, c.LastName, c.Email, d.institution };

确保联接条件两侧的类型具有相同的Case。(对于C#)