setting context lazyloadingenabled false with eager loading

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
curelom
Posts: 19
Joined: Wed 17 Feb 2010 21:10

setting context lazyloadingenabled false with eager loading

Post by curelom » Mon 02 May 2011 20:09

using Devart.Data.Oracle.Entity version 6.10.141.0

I'm using some includes to use eager loading. This seems to only work when LazyLoadingEnabled is set to false in the model itself.
If the model has LayLoadingEnabled = true and I set it to false in the below code where I'm doing my queries, it doesn't work. I don't want to disable lazy loading on the model as I only want to use eager loading in a few cases. Are there any workarounds?

ctx.ObjectContext.ContextOptions.LazyLoadingEnabled = false;
var data = ctx.ObjectContext.FullyLoadedCosts.Include("FlcCategory").Include("Transportation").Where(e => regionRoles.Contains(e.Region));

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Thu 05 May 2011 10:04

If lazy loading is disabled, related objects are not loaded when they are accessed through a navigation property (MSDN).

I have tried the following code - no emps as expected, but there are three emps in dept.Emps when LazyLoadingEnabled = true in the code.

Please try this:
1. Generate EF model with Entity Developer (the Devart Entity Model item) for the following DDL/DML:

Code: Select all

CREATE TABLE DEPT (
  DEPTNO NUMBER(4) CONSTRAINT PK_DEPT PRIMARY KEY,
  DNAME VARCHAR2(14) ,
  LOC VARCHAR2(13)
);

CREATE TABLE EMP (
  EMPNO NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY,
  ENAME VARCHAR2(10),
  JOB VARCHAR2(9),
  MGR NUMBER(4),
  HIREDATE DATE,
  SAL NUMBER(7,2),
  COMM NUMBER(7,2),
  DEPTNO NUMBER(4) CONSTRAINT FK_DEPTNO REFERENCES DEPT
);

INSERT INTO DEPT VALUES  (10,'ACCOUNTING','NEW YORK');
INSERT INTO EMP VALUES
(7782,'CLARK','MANAGER',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,NULL,10);
INSERT INTO EMP VALUES
(7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10);
INSERT INTO EMP VALUES
(7934,'MILLER','CLERK',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,NULL,10);
2. Set Lazy Loading Enabled = true in the model.
3. Run the code:

Code: Select all

    using (MyEntities context = new MyEntities()) {
        context.ContextOptions.LazyLoadingEnabled = false;
        var dept = context.Depts.Where(c => c.Deptno == 10).FirstOrDefault();

        // If lazy loading was disabled, no Emps would be loaded for the contact.
        foreach (Emp emp in dept.Emps) {
            Console.WriteLine(emp.Empno);
        }
    }
How should we modify this sample to reproduce the issue?
Notify us about the results.

curelom
Posts: 19
Joined: Wed 17 Feb 2010 21:10

Lazy Loading/Eager Loading

Post by curelom » Wed 11 May 2011 15:44

I know what Lazy Loading is. My point is that I'm getting different behavior between changing the LazyLoadingEnabled to false on the model and changing it programattically. It should behave the same for both.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 13 May 2011 15:11

I have performed some tests using both design and run time LazyLoadingEnabled properties. I have found no difference in the behaviour.
Could you please send us a small test project illustrating the difference?

Post Reply