OrderBy for children in LINQ request

Possible duplicate:
EF4 LINQ Ordering Parent and all child collections with Eager Loading (.Include ())

Hello to all

I have a custom object that contains a one to many relationship with a role object

So with this linq expression:

from user in USER_TABLE.Include("USERROLE_TABLE") order by user.Name select user 

I can get users with related roles as a child. My problem is that I want the roles of each user to be sorted in alphabetical order. How can i do this? I googled a lot and found nothing

Thanks in advance!

+4
source share
1 answer

So, to clarify, you have a table that includes:

 Name : Role -------------- Bob : leader Jane : scribe Bob : technician Bob : programmer Jane : entity Bob : adept 

and you want to end up with:

 Bob : adept Bob : leader Bob : programmer Bob : technician Jane : entity Jane : scribe 

If so, then you are looking at "orderby, thenby", which in LINQ, it seems to me, is indicated by a comma in this part of the LINQ statement:

 orderby user.Name, user.Role 

Is this what you are looking for?

+1
source

Source: https://habr.com/ru/post/1334926/


All Articles