Theninclude of a List

Asked

Viewed 67 times

2

I have an entity called Team (image 1) which in turn has a Icollection of Userteam (image 2) which in turn has a Icollection Applicationuser called Member.

Goal: return a list of Teams with their Members

Restriction: I cannot change the structure of the entities.

Parlance: c-Sharp
Framework: dotnet Core 2.0

var query = _context.Team.AsQueryable().AsNoTracking() 
.Include(x => x.Account) 
.Include(x => x.UserTeam) 
.Where(x => x.Id == teamId && x.Deleted == false);

Team

Team

query

  • What is the problem? Ps.: avoid using images and present your code as text in the question. It is always important to have a [MCVE]

  • Leandro Angelo, just read the goal to understand. The important code was written in the question. Are you sure you read every question ?

  • It would not put a . Tolist() after the Where ?

  • No. We usually use Include to do "Join" but when there is more than one level (Userteam Include and Member Include in Userteam), I don’t know how to solve.

  • @Carlinhos, no, the images are blocked here, so it is important to include the code as text

  • @Leandroangelo block stackoverflow is slutty heim ? rs

  • 1

    The images are not hosted in the stack overflow and it is common to block them. To avoid interventions, negative votes and deletions always try to add the codes as text and properly formatted.

Show 2 more comments

1 answer

6


I don’t know if I understand this correctly, but I think you’re looking for team members at the same appointment. Use .ThenInclude(p => p.Member) to make the Userteam and Member Join:

var query = _context.Team.AsQueryable().AsNoTracking() 
            .Include(x => x.Account) 
            .Include(x => x.UserTeam)
                 .ThenInclude(p => p.Member)
            .Where(x => x.Id == teamId && x.Deleted == false);
  • That’s right. The problem is that it wasn’t showing up in Tellisense when you were mounting the lambda expression but even without showing up, it works. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.