1

I am working with MS entity-framework core and I am trying to do a eager loading query. For that I have the following method:

public FieldSet GetFieldSetById(int id)
{
    return _context.FieldSet.Include("FieldSetFields.Field").SingleOrDefault(fs => fs.FieldSetId == id);
}

this code works fine, but I was wondering how can I achieve it using the lambda syntax (System.Func).

So far I have this one that works as well, but does not include the "Field".

return _context.FieldSet.Include(e => e.FieldSetFields).SingleOrDefault(fs => fs.FieldSetId == id);

FieldSetFields is a list, and then I cannot call .Field. How can I achieve this?

1 Answer 1

1

Use ThenInclude:

return _context.FieldSet
    .Include(e => e.FieldSetFields)
        .ThenInclude(fsf => fsf.Field)
    .SingleOrDefault(fs => fs.FieldSetId == id);
Sign up to request clarification or add additional context in comments.

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.