LINQ returning Null while same query when write in SQL return 结果

LINQ returning Null while same query when write in SQL return result

我有两个表 Survey_ResponseQuestions

Survey_Response 中的列是:

ID PK
SurveyID FK
QuestionID FK
Response varchar
FilledBy FK

Questions 中的列是:

ID PK
Text varchar
QuestionType varchar
Options varchar

SQL 工作正常的服务器查询:

select * 
from Survey_Response SR
inner join Questions q on SR.QuestionID = q.ID
where SR.SurveyID='1008'

返回空值的 LINQ 是,

    ResponseList = (from r in ObjectSur.Survey_Response
                    join q in ObjectSur.Questions on r.SurveyID equals q.ID
                    where r.SurveyID.Equals(prefix)
                    select new ResponseViewModel
                    {
                        QuestionID = r.QuestionID,
                        Text = q.Text,
                        Response = r.Response,
                        FilledBy = r.FilledBy
                    }).ToList();

我认为这两个查询是相同的。

希望得到您的建议。

谢谢

这两个查询与您在 SQL 中的 QuestionID加入 然后在 Linq

中加入 SurveyID 不同
ResponseList = (from r in ObjectSur.Survey_Response
                join q in ObjectSur.Questions on r.QuestionID equals q.ID //<-- change here
                where r.SurveyID.Equals(prefix)
                select new ResponseViewModel
                {
                    QuestionID = r.QuestionID,
                    Text = q.Text,
                    Response = r.Response,
                    FilledBy = r.FilledBy
                }).ToList();