locked
System.Data.Objects.ObjectContextOptions does not contain a definition for DeferredLoadingEnabled RRS feed

  • Question

  • I am working with a sample Entity Framework class library project that uses POCO classes (and an old Northwind-2000 db that I am running on SqlExpress 2012).  This project was created in VS2010 with EF4.1.  I have VS2012 with EF5.0 and EF6.1.  When I try to compile one of the library classes (NorthwindPocoTest) I receive the following error message (images of the error below):
    >>
    Error 5 'System.Data.Objects.ObjectContextOptions' does not contain a definition for 'DeferredLoadingEnabled' and no extension method 'DeferredLoadingEnabled' accepting a first argument of type 'System.Data.Objects.ObjectContextOptions' could be found (are you missing a using directive or an assembly reference?)
    <<

    What changes can I make so that this library will compile?  The other two libraries in the project compile OK.  Can I change something in the project?  Are there any configurations I can change in VS2012?

    -----------------------------------------------


    Rich P

    Monday, November 17, 2014 6:51 PM

Answers

  • There is no DeferredLoadingEnabled property on the ObjectContextOptions class. You probably want to set the LazyLoadingEnabled property:

    context.ContextOptions.LazyLoadingEnabled = true;

    Or you could just get rid of the that code since laxy loading is enabled by default.

    Deferred loading is a LINQ-to-SQL thing: http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.deferredloadingenabled(v=vs.110).aspx

    Please remember to mark helpful posts as answer and please don't post several questions in the same thread. A new question deserves a new thread.

    • Proposed as answer by Fred Bao Tuesday, November 25, 2014 9:29 AM
    • Marked as answer by Fred Bao Wednesday, November 26, 2014 9:44 AM
    Monday, November 17, 2014 10:52 PM

All replies

  • I noticed that if I comment out the code in the

    public void QueryForCategoryAndLazyLoadProducts()
    {
      // ...
    }

    procedure -- then this library class compiles.  Also, this library is a unit test, if that makes any difference.  But I would still like to know about

    context.ContextOptions.DeferredLoadingEnabled = true;

    I think this has something to do with Lazy Loading.  Any thoughts appreciated.


    Rich P

    Monday, November 17, 2014 10:39 PM
  • There is no DeferredLoadingEnabled property on the ObjectContextOptions class. You probably want to set the LazyLoadingEnabled property:

    context.ContextOptions.LazyLoadingEnabled = true;

    Or you could just get rid of the that code since laxy loading is enabled by default.

    Deferred loading is a LINQ-to-SQL thing: http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.deferredloadingenabled(v=vs.110).aspx

    Please remember to mark helpful posts as answer and please don't post several questions in the same thread. A new question deserves a new thread.

    • Proposed as answer by Fred Bao Tuesday, November 25, 2014 9:29 AM
    • Marked as answer by Fred Bao Wednesday, November 26, 2014 9:44 AM
    Monday, November 17, 2014 10:52 PM