首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么将这个sql转换为linq

2012-01-31 
如何将这个sql转换为linqsql语句select*fromViewstscorewhere stu_idin(selectstu_idfromViewstscore grou

如何将这个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); 

热点排行