日期:2014-05-20  浏览次数:20615 次

如何将这个sql转换为linq
sql语句

select * from Viewstscore where stu_id in (select stu_id from Viewstscore group by stu_id having count(*)>1)
目的

视图Viewstscore中 字段的值可能有重复,我要查找Viewstscore 中stu_id有 重复的数据,用linq不知如何写



------解决方案--------------------
C# code
var query = Viewstscore.Where(y => (from x in Viewstscore group x by x.stu_id into g select g.Key).Contains(y)).Select(x => x);

------解决方案--------------------
C# code
var query = Viewstscore.Where(y => (from x in Viewstscore group x by x.stu_id into g select g.Key).Where(z => z.Count() > 1).Contains(y)).Select(x => x);