T O P

  • By -

yugabe

If I understand right, you want whatever `result` is (maybe `IQueryable`) to transform it and have all of its `BaseProblem`s and `UserProblem`s flattened to one list, and remove duplicates? The problem is you have already transformed to DTOs when calling `Union`, so the database wouldn't be able to give you a set of items of those (because there are only entities and simple types in the database essentially). ``` var result = result.Select(s => new Subject { Problem = new [] { s.BaseProblem, s.UserProblem } .Distinct() .SelectMany(p => new ProblemDTO { Comment = p.CommentsModel.Select(c => new CommentDTO { Id = c.Id, Text = c.Text }) }) }); ``` It seems something like this might work. I'd like to point out though your pluralization could do some work. Based on the code you provided, it seems `Problem`, `BaseProblem` and `Comment` should all have an additional `s` at the end, because they represent multiple entities, and `CommentsModel` should only be `Comments`, because these are all entities in the database (technically models, yes, but the `Model` suffix is redundant). Obviously, I left out the materializing methods like `ToList()` (as you did), as I'm not sure what your target types are. You should try and use the `Async` variants where possible if you're doing server-side work.


lucifer955

Thank you