几行linq.为什么不能这样写?
C# code
var v = from q in dc.bei
group q by q.tbid into g
where g.Count() > 1
select q;
报错:select q;这里的q 说不存在.
我想找出bei表里.tbid重复的所有行.要怎么写?
我是想删除这些重复的.(只留一个就好).
------解决方案-------------------- var v = from q in dc.bei
group q by q.tbid into g
where g.Count() > 1
select g.Key;
------解决方案--------------------至于为什么不能这么写 你要看看SQL语法了
和此LINQ对应的SQL语句
------解决方案-------------------- var v = from q in dc.bei
group q by q.tbid into g
where g.Count() > 1
select g.Take(1);
------解决方案-------------------- var v = from q in dc.bei
let id=dc.bei.GroupBy(p=>q.tbid).Where(p=>p.Count() > 1).Select(p=>p.Key)
where id.Contains(q.tbid)
select q;
------解决方案--------------------试试4L的代码
不行的话用下面的:
var v = (from q in dc.bei
group q by q.tbid into g
where g.Count() > 1
select g).ToList().Select(x => x.Take(1));