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

这样的Linq该怎么写?请教大神
有一条SQL语句如下:


"select Number,max(EffectiveDate) EffectiveDate from TableA 
WHERE EffectiveDate<=('2012-11-26 00:00:00.000')
group by Number"

转换成Linq,该如何写呢?小弟刚接触Linq ,想请教各位大神

------解决方案--------------------

DateTime dt = DateTime.Parse("2012-11-26");
var list = from a in TableA 
                           where a.EffectiveDate<= dt
                           group a by a.Number into g
                           
                           select new
                           {
                               Number = g.Key,
                               EffectiveDate = g.Max(a => a.EffectiveDate)
                           };

------解决方案--------------------


var query=from t in db.TableA
          where t.EffectiveDate.CompareTo(Convert.ToDateTime("2012-11-26 00:00:00.000"))
          group t by t.Number into g
          select new