Entity Framework 5.0, Visual Studio 2012 Navigation Property load issue RRS feed

  • Question

  • I am using Visual Studio 2012, Entity Framework 5.0 and .Net 4.5.

    I have an issue, very intermittently when using navigation properties. Basically, I have a table that has two columns that have foreign keys to a table called ASSET. In the data model for the second table called DOCUMENT, I have ASSET & ASSET1 that are the automatically generated names for the two references to the ASSET table. In one particular case, I get a "Object reference not set to an instance of an object" error when I call _doc.ASSET even though the underlying _doc.assetprimary column is correctly populated. If I am in debug mode in and check my local variables, _doc.ASSET is "nothing" which makes sense, given the error is on _doc.ASSET.DisplayName (a readonly property on the data model). But if I check _doc.ASSET1 and then check _doc.ASSET again, it is now populated and the navigation property is all set. Further, if I expand the _doc local variable to see all underlying properties in the local variable window, this will also populate the navigation property.

    Is this an entity framework 5 or VS 2012 issue? This code worked fine in VS2010, EF 4. Is there a way I can get around it? I tried explicitly associating the DOCUMENT instance with the context, to no avail. It does not seem to be a context issue.



    Tuesday, October 2, 2012 10:53 PM

All replies

  • Hi Joseph,

    Are you using CodeFirst?, does the EnableLazyLoading options is set to true? are your entity classes POCO?

    try to respond to those questions so i can give you help.


    Wednesday, October 3, 2012 7:11 AM
  • Hey Massimiliano,

    I am not using CodeFirst. EnableLazyLoading is set to true. And my entity classes are POCO.

    Monday, October 8, 2012 4:51 PM
  • Hi Joseph,

    If it is convenient, could you please show us the specific database schema and the the related code snippet of your application? I am trying to reproduce your problem.

    Have a nice day.

    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, October 9, 2012 7:41 AM