locked
Navigation Properties not being loaded RRS feed

  • Question

  • Hi,

    I am using VS2010, EF with POCO objects.

    While retrieving entity list the navigation properties are not being loaded although the foreign key is not null. Please see the highlighted parts of the image attached below.

    Is there any additional step to populate the navigation property? Am I missing something?

    Regards,

    Issue: EF Navigation Property


    Paradise lies at the feet of thy mother. - Prophet Mohammed (PBUH) (skype: ali.net.pk)

    Friday, April 6, 2012 6:16 AM

Answers

  • I just learned it that navigation properties are required to be included explicitly while querying through EF.

                    IEnumerable<application> _entityList = context.applications
                        .Include("indb_generalInfo")
                        .OrderBy(p => p.app_code).Skip(pageSize * pageNo).Take(pageSize).ToList();
    
    Although the code above solved the problem, but  now I have too many entities to include like this having more than few columns in many of them. Will it not hit the performance? Comments & Suggestions please.

    Paradise lies at the feet of thy mother. - Prophet Mohammed (PBUH) (skype: ali.net.pk)

    • Marked as answer by Khadim Ali Saturday, April 7, 2012 11:40 AM
    Friday, April 6, 2012 8:12 AM
  • Hi Ali.NET,

    If you don't want to load all the Navigation Properties at the time of the initial query you could use lazy loading, this will perform additional queries as soon as the navigation properties are accessed in order to populate them.

    In terms of performance, it depends greatly on your environment and the number of entities being included in the object graph whether eager or lazy-loading of navigation properties will perform better. Check out the link for more information on things to take into consideration regarding performance when using EF: http://msdn.microsoft.com/en-us/library/cc853327.aspx 

    Regards,

    Tyler

    • Marked as answer by Khadim Ali Saturday, April 7, 2012 11:40 AM
    Friday, April 6, 2012 1:17 PM

All replies

  • I just learned it that navigation properties are required to be included explicitly while querying through EF.

                    IEnumerable<application> _entityList = context.applications
                        .Include("indb_generalInfo")
                        .OrderBy(p => p.app_code).Skip(pageSize * pageNo).Take(pageSize).ToList();
    
    Although the code above solved the problem, but  now I have too many entities to include like this having more than few columns in many of them. Will it not hit the performance? Comments & Suggestions please.

    Paradise lies at the feet of thy mother. - Prophet Mohammed (PBUH) (skype: ali.net.pk)

    • Marked as answer by Khadim Ali Saturday, April 7, 2012 11:40 AM
    Friday, April 6, 2012 8:12 AM
  • Hi Ali.NET,

    If you don't want to load all the Navigation Properties at the time of the initial query you could use lazy loading, this will perform additional queries as soon as the navigation properties are accessed in order to populate them.

    In terms of performance, it depends greatly on your environment and the number of entities being included in the object graph whether eager or lazy-loading of navigation properties will perform better. Check out the link for more information on things to take into consideration regarding performance when using EF: http://msdn.microsoft.com/en-us/library/cc853327.aspx 

    Regards,

    Tyler

    • Marked as answer by Khadim Ali Saturday, April 7, 2012 11:40 AM
    Friday, April 6, 2012 1:17 PM