How to create an OpenAccessContext instance using a fluent API

Tuesday, Nov 11, 2014 22:13 · 60 words · 1 minute read

The Goal

Creating a new OpenAccessContext using a fluent API.

The Setup

To be able to create a new OpenAccessContext instance using fluent API means you should install the Telerik DataAccess Context Extensions nuget:

Install-Package MayLily.DataAccess.ContextExtensions

Now it is very easy to instantiate a context instance:

var context = Db.Init()
.ConnectionString(c => c.LoadFromConfig("NorthwindConnection"))
.BackendConfiguration(b => b.LoadFromConfig("MssqlConfiguration", ConfigurationMergeMode.ConfigFileDefinitionWins))
.MetadataContainer(m => m.Source<MyMetadataSource>().NullForeignKey())
.FetchStrategy(fs => { })
.CacheKey("SampleKey")
.Build<MyContext>(migrateSchema: true);

Further information regarding the API and how to use it, can be found here.