Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove repeatable items in linq query

Tags:

c#

listOrders.DataSource = (from sp in dbdata.Specifications
                         join ord in dbdata.Orders on sp.O_id equals ord.O_id
                         join prd in dbdata.Products on ord.O_id equals prd.O_ID
                         where sp.Approve == "Yes" && 
                         sp.Awailable_BOM == "Yes" && 
                         prd.Hours_prd == null
                         orderby sp.O_id descending
                         select sp.O_id).Distinct();

in here I am tring to get desceding values. But it always gets ascending values. if I remove "Distinct()" it works properly but after adding "Distinct()" this problem occurs.

like image 731
Muditha Avatar asked Nov 30 '25 12:11

Muditha


1 Answers

Try this:

listOrders.DataSource = (from sp in dbdata.Specifications
                         join ord in dbdata.Orders on sp.O_id equals ord.O_id
                         join prd in dbdata.Products on ord.O_id equals prd.O_ID
                         where sp.Approve == "Yes" && 
                         sp.Awailable_BOM == "Yes" && 
                         prd.Hours_prd == null
                         select sp.O_id).Distinct().OrderByDescending();
like image 140
tallseth Avatar answered Dec 03 '25 01:12

tallseth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!