Reputation: 19386
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.
Upvotes: 3
Views: 1113
Reputation: 107317
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;
}
Upvotes: 1
Reputation: 1568
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?
==new EDIT==
Upvotes: 3
Reputation: 44308
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
Upvotes: 1