我有两个表Survey_Response
和Questions
。
Survey_Response
中的列是:
ID PK
SurveyID FK
QuestionID FK
Response varchar
FilledBy FK
Questions
中的列是:
ID PK
Text varchar
QuestionType varchar
Options varchar
SQL Server查询工作正常:
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();
我认为两个查询都是相同的。
希望得到您的建议。
谢谢
答案 0 :(得分:2)
这两个查询与您在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();