Get Distinct rows From C# Data Table with LINQ Comprehensive Query -
i have info table of c#.just want distinct row list on column property of info table.say , have info table columns property x,y & z.i have rows 200 in info table have same x values. want have distinct row based on x column property linq comprehensive query binding list of model (i have).
i have model
public class model { public model(string x) { x= x; } public int x{ get; set; } public string y{ get; set; } public decimal z{ get; set; } }
and stuck comprehensive query.it should give distinct list not working expected.
list<model> modellist= new list<model>(); modellist= (from item in response.asenumerable() select new { description = datatableoperationhelper.getstringvalue(item, "description") }).distinct().select(m => new model(m.description)).tolist();
where datatable response ( has 200 rows) , 'description' 1 of column property. it gives list not distict value of 'description' property.is there missing consider ? stuck .
it's because code
new { description = datatableoperationhelper.getstringvalue(item, "description") }
creates new object property "description" , compares reference not value of "description".
try this:
modellist = response.asenumerable() .select(item=>datatableoperationhelper.getstringvalue(item, "description")) .distinct() .select(x => new consumablesviewmodel(x.description)) .tolist();
c# linq datatable
No comments:
Post a Comment