How To Sort orderbydesecending in List Of List of List LINQ c# [Resolved]

Posted by Kasani007 under LINQ on 7/27/2016 | Points: 10 | Views : 1300 | Status : [Member] | Replies : 2
I Had Written As Below:

schoolsList.studentList.Select(x=>(x.Address.Address1).OrderByDescending(x.Address.AddressId)).Distinct().ToList());


It Is Showing

Error:
The type arguments for method
'System.Linq.Enumerable.OrderByDescending<TSource,TKey>(System.Collections.Generic.IEnumerable<TSource>,System.Func<TSource,TKey>)'
cannot be inferred from the usage. Try specifying the type arguments explicitly.




Responses

Posted by: Rajnilari2015 on: 7/29/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Try

schoolsList
.studentList
.Select(x=>x.Address)
.Select(s=>new {s.Address1, s.AddressId })
.OrderByDescending(o=>o.AddressId)
.Select(x=>x.Address1)
.Distinct()
.ToList();


Hope that helps

--
Thanks & Regards,
RNA Team

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheonarayan on: 7/27/2016 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Your linq query is wrong it seems.
schoolsList.studentList.Select(x=>(x.Address.Address1).OrderByDescending(x.Address.AddressId)).Distinct().ToList());


It should be
schoolsList.studentList.Select(x=>x.Address.Address1).OrderByDescending(x => x.Address.AddressId)).Distinct().ToList());


Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response