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));
setting context lazyloadingenabled false with eager loading
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:
2. Set Lazy Loading Enabled = true in the model.
3. Run the code:
How should we modify this sample to reproduce the issue?
Notify us about the results.
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);
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);
}
}
Notify us about the results.
Lazy Loading/Eager Loading
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.