[c#]转换 SQL '不入' 到 LINQ to 实体使用实体框架 4

发布时间: 2017/2/26 18:57:54
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

如何转换 SQL 与 '不在' 关键字到 LINQ 到实体使用实体框架 4? 以 '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' ))

  )

解决方法 1:

这样试试︰

 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()))
赞助商