翻译SQL 'not in'使用实体框架将LINQ转换为实体

本文关键字:实体 框架 转换 LINQ SQL not in 翻译 | 更新日期: 2023-09-27 18:13:03

如何使用实体框架4将SQL与'not in'关键字转换为LINQ到实体?所有以"ID"结尾的字段都是整数类型。

SELECT * 
        FROM IRSampleCompletionGoal as goal_tbl
  where 
  (Cast(goal_tbl.[TermID] as nvarchar) +' '+Cast(goal_tbl.[UserID] as nvarchar)+' '+Cast(goal_tbl.[CourseID] as nvarchar)+' '+cast(goal_tbl.[StudentID] as nvarchar)+' '+cast(goal_tbl.[ObjectiveID] as nvarchar))  
  NOT IN
  (
  select (Cast([TermID] as nvarchar) +' '+Cast([UserID] as nvarchar)+' '+Cast([CourseID] as nvarchar)+' '+cast([StudentID] as nvarchar)+' '+cast([ObjectiveID] as nvarchar)) 
  from IRSampleCompletionCurrentStatistics
  where ((ArtifactID is not null) OR (NoArtifactChecked='True' ))
  )

翻译SQL 'not in'使用实体框架将LINQ转换为实体

试试这样:

 goal_tbl.Where(x => !IRSampleCompletionCurrentStatistics.Where(i => i.ArtifactID != null || i.NoArtifactChecked == true).Any(i => (i.TermID.ToString() + " " + i.UserID.ToString() + i.StudentID.ToString() + " " + i.ObjectiveID.ToString()) == (x.TermID.ToString()+ " " + x.UserID.ToString() + " " + x.CourseID.ToString() + " " + x.StudentID.ToString() + x.ObjectiveID.ToString()))