Convert SQL statement to Linq-2-Sql
How do I translate the following SQL statement into L2S?
SELECT DefaultCode, MAX(Effect开发者_如何学编程iveDt) AS EffectiveDt
FROM tblDF_DefaultSetting
GROUP BY DefaultCode
You want to use the GroupBy
operator on DefaultCode
and use the Select
operator to create a new anonymous type with the two values you're interested in.
dataContext.tblDF_DefaultSetting
.GroupBy(x => x.DefaultCode)
.Select(x => new { DefaultCode = x.Key, EffectiveDt = x.Max(x => x.EffectiveDt) });
精彩评论