Databases Reference
In-Depth Information
context.ContextOptions.LazyLoadingEnabled = true;
return context;
}
Notice that this example is a bit contrived because you would normally want to rely on
the Entity Framework designer, which allows you to choose the default lazy loading
option and generate this initialization code as part of the NorthwindEntities constructor.
However, it doesn't hurt to explicitly do this in a Dynamic Data application, which bene-
fits from lazy loading if you share the data model with other developers, who prefer to
have it turned off by default.
When your application uses a LINQ-enabled data access framework other than Entity
Framework or LINQ to SQL, you need to use the RegisterContext method that takes a
DataModelProvider instance instead of the context class. A DataModelProvider is an
object that can extract metadata from a data model and present it to the Dynamic Data
metadata API in a format it can consume. Internally, Dynamic Data implements a separate
DataModelProvider for each Entity Framework and LINQ to SQL and gives you the ability
to create your own provider to support third-party frameworks, such as SubSonic,
LightSpeed, and LinqConnect.
In addition to the three overloads of the RegisterContext method discussed here,
MetaModel class also includes a second set of similar methods with two parameters each,
where the second parameter is a ContextConfiguration object. You will most commonly
use these methods during the initial development stages of your application to make all
tables in your model visible by default:
public static readonly MetaModel DefaultModel = new MetaModel();
void Application_Start(object sender, EventArgs e)
{
var configuration = new ContextConfiguration();
configuration.ScaffoldAllTables = true;
DefaultModel.RegisterContext(typeof(NorthwindEntities), configuration);
}
It is probably not a good idea to leave this code in a production application, where you
normally want to limit user interface to only those tables you actually want your users to
access to prevent confusion and accidental data corruption.
Accessing MetaTable Objects
When the RegisterContext method is called, the MetaModel uses a data model provider to
obtain information about tables the data model supports and creates MetaTable objects to
represent them. When the registration is complete, you can access the tables using a
number of different properties and methods:
public ReadOnlyCollection<MetaTable> Tables { get; }
public List<MetaTable> VisibleTables { get; }
 
Search WWH ::




Custom Search