SQL:
SELECT TOP 1 min(id) BAGID FROM A group by id having count(id)=1 ORDER BY id ASC
LINQ这么写。在网上查了很多,好像就是一篇,对着抄袭。
------解决方案--------------------------------------------------------
var query=( from a in db.A
group a by a.id into g
where g.Count()==1
order by g.Key
select new {BAGID =g.Min(x=>x.id)}).FirstOrDefault();
------解决方案--------------------------------------------------------
int minid = (from t in dc.Class1 group t by t.id into g where g.Count() == 1 order by g.Key select new { bagid = g.Key }).Min(t => t.bagid);