c# - Get all Parents, but only one son and one grandson for a condition -
i have structure:
topics.subtopics.events topics.users users.topics
topics
, users
many-to-many relationship.
i want retrieve topics, subtopics , events premieredatetimeinutc
(property of event) equal or greater yesterday
, topics.users.id == userid
. 1 event should retrieved (the first 1 yesterday) each topic. , subtopic parent of event. topic must returned ones don't have , subtopic , event.
i tried far:
return context.topics .include( t => t.subtopics.select( s => s.events .any(e => e.premieredatetimeinutc >= datetime.today.adddays(-1)) ) ) .where(t => t.users.any(u => u.id == userid)).tolist();
but doesn't work. exception: "the include path expression must refer navigation property defined on type. use dotted paths reference navigation properties , select operator collection navigation properties. parameter name: path".
var yesterday =datetime.today.adddays(-1); var events = context.events.where(x=>x.premieredatetimeinutc>=yesterday) .groupby(x=>x.subtopic.topicid, (k,g)=>new{ topicid=k, event=g.orderby(e=>e.premieredatetimeinutc).firstordefault() }); var topics = context.topics .where(t=>t.users.any(u=>u.id==userid)) .groupjoin(events, t=>t.id, e=>e.topicid,(t,g)=>new{ topic=t, firstevent=g.firstordefault(), subtopic=g.firstordefault().subtopic });
Comments
Post a Comment