Eager loading including navigational property of derived class RRS feed

  • Question

  • Sample class structure

    class Order
        public int Id { get; set; }     
        public DateTime Date { get; set; }
        public List<OrderDetail> Details { get; set; }
    class OrderDetail
        public int Id { get; set; }
        public int Qty { get; set; }
        public Item Item { get; set; }
    class Item
        public int Id { get; set; }
        public string Name { get; set; }
    class ElectronicItem : Item
        public MoreDetail Detail { get; set; }
    class MoreDetail
        public int Id { get; set; }
        public string SomeData { get; set; }

    In order to populate order object with all navigational properties, I wrote


    I also want to load MoreDetail object, hence I tried


    It didn't work. How to load complete Order object?


    Thursday, August 16, 2012 5:38 PM

All replies

  • Hi,

    Just doing context.Orders.Include("Details.Item") should eagerly load the data for want, so the first include isn't necessary. But I don't think having that should have caused it to not work.

    What exactly happened? Can you show me the actual query and what the result was?

    Which version of EF you are using might be helpful as well.


    Just do that  you have it, information on various ways of loading data is here:

    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    Friday, August 17, 2012 4:38 PM