The following answer relates to a Database-First or Model-First workflow (only the two workflows that were available with the Entity Framework (version <= 4.0) when the question was asked). If you are using the Code-First workflow (which is available from version EF> = 4.1), go to ssmith answer to this question for the right solution.
The edmx file has an attribute for lazy loading in the definition of <ConceptualModel> and <EntityContainer> , where you can set the lazy load as a whole to false:
<EntityContainer Name="MyEntitiesContext" annotation:LazyLoadingEnabled="false">
The following parameter is created in the ObjectContext constructor:
public MyEntitiesContext() : base("name=MyEntitiesContext", "MyEntitiesContext") { this.ContextOptions.LazyLoadingEnabled = false; OnContextCreated(); }
My example does not mean that the generated ObjectContext (or DbContext in newer versions of EF) needs to be edited manually (which will be replaced by each update of the model from the database, as ctorx noted), but this is the EntityContainer element in the edmx:ConceptualModels section of the edmx:ConceptualModels file should be edited. adding the annotation:LazyLoadingEnabled="false" attribute annotation:LazyLoadingEnabled="false" - either manually in the XML editor or on the constructor surface properties page, where this parameter is also available. This modification of the EDMX file automatically generates a context class with disabled lazy loading in the constructor, as shown above. Modification of the EDMX file itself is not overwritten when the model is updated from the database.
Slauma Jun 03 '10 at 15:51 2010-06-03 15:51
source share