c# - How to make Distinct... More distinct? -
ok, aside silly title. have query pulling distinct values including departmentid column instead of departmentname column distinct. makes me causes duplicates.
viewbag.departmentlist = docs.select(m => new selectlistitem { value = sqlfunctions.stringconvert((double)m.departmentid).trim(), text = m.departmentname }) .distinct(); // fill viewbag unique list of 'department's table. here docs has inside it:
if helps @ all, departmentid primary key. departmentid 1 point same name , on.
you can use iequalitycomparer
class mycomparer<t> : iequalitycomparer<t> t : selectlistitem { public bool equals(t x, t y) { return x.value == y.value ; } public int gethashcode(t obj) { return obj.id.gethashcode(); } } then code
viewbag.departmentlist = docs.select(m => new selectlistitem { value = sqlfunctions.stringconvert((double)m.departmentid).trim(), text = m.departmentname }) .distinct(new mycomparer<selectlistitem>()).tolist(); 
Comments
Post a Comment