Reputation: 672
I know based on several articles from MSDN that you simply add:
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
In the context.cs file that accompanies the EDMX file or edit context.tt file to have those lines added when you regen the edmx files.
However, I have noticed that when the database fields change (specifically deleting them), and the ADO.NET files are replaced, the changes have to be remade. Is there a place I can permanently add those lines to be included with my context.cs file when I have to recreate the ADO.NET files?
I did notice that this article on SO is close to this issue, but no where near:
Disable lazy loading by default in Entity Framework 4
Upvotes: 0
Views: 750
Reputation: 6219
The class that EDMX generate is partial, so you can write code in this class in another file.
So you will create another file, and its content you will "create" same class like that:
namespace Same.Namespace.FromOtherContextClass
{
public partial class Context : DbContext
{
public Context()
{
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
}
}
}
Remember, you must have same namespace in this file.
Upvotes: 5
Reputation: 672
@AlbertoMonterio had the right idea.
here is the code that works:
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using CorporateWeb.API.Model;
namespace CorporateWeb.API.DAL
{
public partial class context : DbContext
{
public context() : base("name=Corporate_WebEntities")
{
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
}
}
}
Upvotes: -3