asp.net mvc - Use LINQ to Access All the Collections of a Collection on My Model? -
i trying write property on model, accessor can return collection comprised of collections each member of collection property contains.
so:
document.lines collection of line objects. each line has many many relationship documents called relateddocuments. able access collection of relateddocuments every line in document. there way in linq/ef?
i trying without creating dbcontext object in model.
long form this:
public list<relateddocument> relateddocuments { { var rds = new list<relateddocument>(); foreach (var line in lines) { foreach (var rd in line.relateddocuments) { if (!rds.contains(rd)) { rds.add(rd); } } } return rds; } }
i'm not quite sure issue is; if lines
ienumerable<t>
(and using system.linq
), wouldn't like
var allrelated = lines .selectmany(line => line.relateddocuments) .distinct();
suffice?
of course, lines
has come somewhere ..
Comments
Post a Comment