如何编写Linq查询以根据月份从表中获取不同的学生ID。
答案 0 :(得分:1)
以下是您要找的内容:
var ids = context.Students.Where(s => s.CreationDate.Month == 1 && s.CreationDate.Year == 2013).Select(s => s.Id).Distinct().ToList();
答案 1 :(得分:0)
不是testet,但对于DataTable来说它看起来应该是这样的:
int year = 2013, month = 1;
var test = db.AsEnumerable().Where(x => x.Field<DateTime>("Date").Year == year && x.Field<DateTime>("Date").Month == month).GroupBy(y => y.Field<id>("ids")).Select(z => z.First());