3

I have created an edmx and in the designer.cs file I have 3 constructors. In each constructor I add the followiing line:

this.Configuration.LazyLoadingEnabled = false;

However when I create a new DBContext the lazy loading is enabled because when I create a new DBContext is not used any of this constructors.

Which constructors is used to create a new DBContext?

EDIT: I am not using code first. I create my edmc from a SQL Server database.

Thanks.

3 Answers 3

3

You can go to the EDMX file, properties, and there's a property Lazy Loading. Just put it to false.

Regards,

==============EDIT===============

Don't you have this? enter image description here

==new EDIT== enter image description here

Sign up to request clarification or add additional context in comments.

11 Comments

@ÁlvaroGarcía You have to click in the designer. What you see are the properties of 'just the file', not the properties of the current active object in the designer.
You have to open the edmx, and then press F4 (for properties)
Did you made a clean solution and rebuild? do you create the dbcontext how? like this: using (SergioEntities dm = new SergioEntities()) { }
and when you put a breakpoint like i did in the image you see lazyloading = true?
Then I don't understand. I have this: using (SergioEntities dm = new SergioEntities()) { bool test = dm.Configuration.LazyLoadingEnabled; } and test gives me false! I have just created a EDMX, add a table, and have put Lazy Loading Enable to false. It works...
|
1

I think there's a property on the EDMX design time canvas properties to disable lazy loading. The edmx file has in the ConceptualModel and EntityContainer definition an attribute for lazy loading where you can set lazy loading generally to false:

<EntityContainer Name="MyEntitiesContext" annotation:LazyLoadingEnabled="false">

ref: Disable lazy loading by default in Entity Framework 4

1 Comment

I have this line: <EntityContainer Name="CMMSModelSqlServerEF44StoreContainer"> but annotation gives me an error: the prefix is not definied.
1

The property on the edmx design properties is called LazyLoadingEnabled - it defaults to true.

This is used in the T4 template (MyModel.Context.tt) as follows:

public <#=Code.Escape(container)#>()
    : base("name=<#=container.Name#>")
{
<#
    WriteLazyLoadingEnabled(container);
#>
}

Which will write out the following if the property is disabled:

this.Configuration.LazyLoadingEnabled = false;

If FWR the property isn't visible in the EDMX designer, you can remove the conditional code generation, and hard code it:

public <#=Code.Escape(container)#>()
    : base("name=<#=container.Name#>")
{
    this.Configuration.LazyLoadingEnabled = false;
    // more setup here, e.g. this.Configuration.ProxyCreationEnabled = false;    
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.