c# - Linq order by parent and child -


i have 2 tables: feedback , comments. feedback can have many comments. simple parent child relationship.

i have page list feedback , related comments this:

 feedback comment a1 comment a2  feedback b comment b1  feedback c (note: no comments) 

each feedback , comments have created date. @ moment order feedback date , comment date have newest feedback in top , comments after that.

what i'm trying achieve is: when new comment added feedback feedback should displayed in top, no matter how old feedback or if feedback added without comments feedback should first item in list. let's comment added feedback b , after new feedback no comments added, list this:

 feedback d (this new feedback)  feedback b comment b1 comment b2 (this new comment)  feedback comment a1 comment a2  feedback c (note: no comments) 

now feedback d in top of list because has newest date of feedback , comments , feedback b second has comment b2 have second newest date.

this code far:

_repositories.feedback .include(f => f.comments) .orderbydescending(f => f.publisheddate); 

what modify

.orderbydescending(f => f.publisheddate)
correct order. possible?

select last comment date every feedback , sort them:

_repositories.feedback .include(f => f.comments) .orderbydescending(f =>      f.comments     .select(c => (datetime?)c.publisheddate)     .orderbydescending(c => c)     .firstordefault() ?? f.publisheddate ) .thenbydescending(f => f.publisheddate); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -