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

没文化真可怕,哪位帮忙把这个SQL语句翻译成LINQ。。

select * from hotel_HotelLinkRelation
 where id in 
(SELECT min(id) FROM hotel_HotelLinkRelation hhlr 
GROUP BY ExHotelCode,hhlr.GDSCode)


整了好几个小时了,实在是没有办法了,大家帮个忙。。。。。。。。。。。。。。。
------解决方案--------------------
var www =(from b in hotelData.hotel_HotelLinkRelation group b by new
                      {
                          b.ExHotelCode,
                          b.GDSCode
                      } into g
                      select new
                      {
                         minId=g.Min(p=>p.id)
                      }).First().id;

            var result = from a in hotelData.hotel_HotelLinkRelation where a.id ==www select a;

------解决方案--------------------
引用:
SQL code

select * from hotel_HotelLinkRelation
 where id in 
(SELECT min(id) FROM hotel_HotelLinkRelation hhlr 
GROUP BY ExHotelCode,hhlr.GDSCode)



整了好几个小时了,实在是没有办法了,大家帮个忙。。。。。。。。。。。。。。。

试试:
var result = from n in db.hotel_HotelLinkRelation
                         group n by new { n.ExHotelCode, n.GDSCode } into g
                         let z = g.Min(c => c.id)
                         from u in db.hotel_HotelLinkRelation
                         where z.Contains(u.id)
                         select new
                         {
                             u.ExHotelCode,
                             u.GDSCode