2

I have this relationship :

public class Company
{
  public virtual ICollection<Employee> Employee { get; set; }
}

Inside of Employee I have a Profile property:

public class Employee
{
    public virtual Profile Profile { get; set; }
}

I'm able to get all the employees but not the Profile property.

And the request :

var result = await Context.Company.Include(a => a.Employee).Where(a => a.Token == Token).SingleOrDefaultAsync();

The result is retrieved but not the Profile.

2

2 Answers 2

3

as @jcruz pointed out ThenInclude in EF Core is what you want:

var result = await Context.Company.Include(a => a.Employee).ThenInclude(e => e.Profile).Where(a => a.Token == Token).SingleOrDefaultAsync();
Sign up to request clarification or add additional context in comments.

1 Comment

I had found about the ThenInclude but it wasn't working, because the relationship from Profile to Employee one to one was made but in reverse, not is working. Thanks!
0

Change the Include() function to the string overload and include the Profile property.

var result = await Context.Company.Include("Employee.Profile").Where(a => a.Token == Token).SingleOrDefaultAsync();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.