0

我在 linq 中加入表时遇到问题,因为我正在检查templateSetId模板集表中是否存在

询问:

select 
    vc.RowID, Choice_Text, VCE.[Goto] 
from 
    ropes.Validation_Choices vc
left outer join 
    ropes.Validation_Condition_Expression VCE 
      on VCE.ChoiceID = vc.RowID and TemplateSetID in 
                                     (select RowID 
                                      from ropes.Validation_Templates_Set 
                                      where TemplateID = 66)
where 
   vc.QuestionID = 81 

此查询返回 3 行。

移动 templatesetid 的过滤器给我一个错误“运算符'&&'不能应用于'int类型的操作数?' 和'bool'”我能做到的最好的就是这个

from tc in _context.ValidationChoice
     join vce in _context.ValidationConditionExpression
     on tc.ChoiceId equals (int)vce.ChoiceID into lfc
     from lf in lfc.DefaultIfEmpty()
     where  tc.QuestionID == questionId &&
     (from ts in _context.ValidationTemplateSet where ts.TemplateID == templateId     select ts.TemplateSetId).Contains((int)lf.TemplateSetID)


                                 select new TemplateChoiceDTO
                                 {
                                     ChoiceId = tc.ChoiceId,
                                     ChoiceText = tc.ChoiceText,
                                     NextQuestionId = lf.Goto

                                 };

这相当于:

 select vc.RowID,Choice_Text,VCE.[Goto] from ropes.Validation_Choices vc
    left outer join ropes.Validation_Condition_Expression VCE on 
    VCE.ChoiceID = vc.RowID 
    where vc.QuestionID = 81 
    and TemplateSetID in (select RowID from ropes.Validation_Templates_Set where TemplateID = 66)

此查询返回 1 行,因为 templatesetid 的过滤器已移到外部

4

0 回答 0