none
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

    context.Orders.Include("Details").Include("Details.Item")

    I also want to load MoreDetail object, hence I tried

    context.Orders.Include("Details").Include("Details.Item.Detail")

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


    Hitesh

    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.

    Thanks.

    Just do that  you have it, information on various ways of loading data is here:http://msdn.microsoft.com/en-us/data/jj574232


    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
    Moderator