0

I have a db model that looks like:

    public CallTrackers()
    {
        CallTrackerCallerTelns = new HashSet<CallTrackerCallerTelns>();
        CallTrackerClients = new HashSet<CallTrackerClients>();
        CallTrackerFlwups = new HashSet<CallTrackerFlwups>();
        CallTrackerHistory = new HashSet<CallTrackerHistory>();
    }

With my GetAll() I am loading everything fine except for CallTrackerClients has 3 nested objects that I can't retrieve:

    public CallTrackerClients()
    {
        CallTrackerClientAdvice = new HashSet<CallTrackerClientAdvice>();
        CallTrackerClientOffences = new HashSet<CallTrackerClientOffences>();
        CallTrackerClientSureties = new HashSet<CallTrackerClientSureties>();
    }

I am trying:

    [HttpGet]
    public IEnumerable<CallTrackers> GetAll()
    {
        return _context.CallTrackers
            .Include(log => log.CallTrackerClients)
                .ThenInclude(c => c.CallTrackerClientAdvice)
            .Include(log => log.CallTrackerCallerTelns)
            .Include(log => log.CallTrackerFlwups)
            .Include(log => log.CallTrackerHistory)
            .ToList();
    }

The above works but I need to get the Sureties and Offences as well. When I try .ThenInclude(c => c.CallTrackerClientOffences)I get some 'does not contain definition' error.

Any ideas how to get the two remaining collections that are part of CallTrackerClients?

1 Answer 1

2

You always have to start from the parent entity.

    return _context.CallTrackers
        .Include(log => log.CallTrackerClients)
            .ThenInclude(c => c.CallTrackerClientAdvice)
        // this
        .Include(log => log.CallTrackerClients)
            .ThenInclude(c => c.CallTrackerClientOffences)
        // and this
        .Include(log => log.CallTrackerClients)
            .ThenInclude(c => c.CallTrackerClientSureties)
        .Include(log => log.CallTrackerCallerTelns)
        .Include(log => log.CallTrackerFlwups)
        .Include(log => log.CallTrackerHistory)
        .ToList();
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.