我的linq查询有问题。
我的查询是这样的:
var results = db.rms_section_vw.Where(s => s.sect_activeflag == true &&
s.dept_isactive == true)
.GroupBy(s => s.sect_id)
.Select(r => r.FirstOrDefault()).ToList();
但仍然在显示记录时,有重复的内容。
我的观点:
Dept ID Sect ID Dept name Sect Name dept_isactive sect_isactive
1 1 Dept 1 Sect 1 1 1
1 2 Dept 1 Sect 2 1 1
显示结果时:
Dept name Sect name
Dept 1 Sect 1
Dept 1 Sect 1 (supposed to be Sect 2)
Dept 2 Sect 3
Dept 2 Sect 3 (supposed to be Sect 4)
我的查询有什么问题?
答案 0 :(得分:0)
var results = db.rms_section_vw.Where(s => s.sect_activeflag == true && s.dept_isactive == true).GroupBy(s => s.sect_id).Select(r => r.FirstOrDefault()).Distinct().ToList();