c# - Linq query biz object to discover unique records..would this be a case for recursion -
not sure how go , hoping brainiacs here point me in right direction. have biz object collection , of course each item in top level collection has properties 1 of properties collection of related child records....and these child records have values looking for.
so high level overview not moving closer...
the parent object collection of events (in essence school classes) , related child collection instructors...such primary, secondary, aide, observer..etc.
now idea create instructor calendar shows events bob..etc has month.
so instructors on left (y axis) of calendar while days of month across top (x axis)....however mentioned instructors have mined out of biz obj.
now @ stage in development can rework biz object if there better way should implement.
now in limited knowledge base best come write foreach loop extract instructors querying 1 @ time...adding results collection , taking new collection , removing dupes or dupe check , don't insert during loop.
something list.foreach(x => x.teammember....???)
the parent object:
public class calendarevent { #region internal fields private readonly string _id; private datetime _start; private datetime _end; private string _eventname; private teammembers _eventteam; #endregion #region const public calendarevent(string id, datetime start, datetime end, string evtname) { this._id = id; this._start = start; this._end = end; this._eventname = evtname; } #endregion #region props public string id { { return _id; } } public datetime start { { return _start; } } public datetime end { { return _end; } } public string eventname { { return _eventname; } } public teammembers eventteammembers { get; set; } #endregion }
the child object teammembers:
public class teammember { #region internal fields private readonly string _firstname; private readonly string _fullname; private readonly string _userid; private teamroles.teammemberrole _memberrole; //private string _resid; #endregion #region const public teammember(string fullname, string firstname, string userid) { this._fullname = fullname; this._firstname = firstname; this._userid = userid; //this._resid = resid; } #endregion #region props public string firstname { { return _firstname; } } public string fullname { { return _fullname; } } public string userid { { return _userid; } } //public string speakerid { { return _resid; } } public teamroles.teammemberrole teammemberrole { get; set; } #endregion }
so object this:
calendarevent.count = 25 calendarevent[0] eventid = guid start = may 1st end = may 12th eventname = pencil sharpening teammembers(.count = 3)
so need extract 3 team members but..if have added them y axis collection (ie collection bound y axis) skip or remove later list.distinct() or similiar.
any ideas, suggestions or best practices appreciated.
my apologies struggling 1 aspect of has been shown me. i'm sure @ ben aaronson has answered going on head.
i understand comment event know teammembers not reverse. understand statement:
"you need store events somewhere. can't start team members , events without having access events @ same time..."
agreed have such collection begin in proposed solution below called _allevents...so hoping pull out distinct collection of teammembers.
for example wrote lack of knowledge means trip around mulberry bush....i had???
list<calendarevent> asdf = _allevents.where(evt => evt.teammembers.any(tm => tm.userid != string.empty)).distinct().tolist();
your solution this:
public ienumerable<calendarevent> eventsforteammember(string userid) { return _allevents.where(e => e.eventteammembers.any(tm => tm.userid == userid)); }
in example, it's assumed have collection possible events in scope called _allevents
. i'm assuming teammembers
sort of collection of teammember
s can perform linq queries on. , if want team members other user id, change should relatively straightforward see.
edit
to pull out distinct list of team members, in updated part of question, you're close, need remember want select team member out of event. like:
public ienumberable<teammember> allteammembersforevents() { return _allevents.selectmany(e => e.eventteammembers).distinct(); }
the key bit here selectmany
, flattens collections.
Comments
Post a Comment