2

I'm trying to do an include of a nested entity. I assumed the below code would work but it does not recognize the CapitalMailOrders entitycollection. Can anyone point me in the right direction to include these?

    var result = db.Contacts
        .Include(a => a.IDXPageLinks)
        .Include(b => b.ReboGatewayLoginInfoes)
        .Include(c => c.SocialMedias)
        .Include(d => d.WebSiteInfoes)
        .Include(e => e.ContactImages)
        .Include(f => f.RealtorSetUpProcesses)
        .Include(h => h.RealtorSetUpProcesses.CapitalMailOrders) // getting compile time error here. Doesn't recognize Entity 
        .Include(g => g.Contact_CarrierCode_Assignments)
        .FirstOrDefault(c => c.ContactID == id);

Thanks

enter image description here

1 Answer 1

1

The extra entity level is accessed from a collection and so you need to add a Select in order to bring all the entries into the include.

.Include(h => h.RealtorSetUpProcesses.Select(h2 => h2.CapitalMailOrders)
Sign up to request clarification or add additional context in comments.

3 Comments

Get the error "A specific Include path is not valid. The entity type does not declare a navigation property with the name CapitalMailOrders". I tried it with "RealtorSetUpProcesses.CapitalMailOrders" and it didn't throw any errors but it didn't include the nested collection.
Does your Contacts entity have a navigation property to RealtorSetupProcesses and does the RealtorSetupProcesses have a navigation property to the CapitalMailOrders?
Thanks @Phil. That worked. I think the main problem was there was no data in the table. After I added record and changed to your updated snippet I was able to look at the collection. Thanks again.

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.