Skip to content

Instantly share code, notes, and snippets.

@sovanesyan
Created October 8, 2010 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sovanesyan/616555 to your computer and use it in GitHub Desktop.
Save sovanesyan/616555 to your computer and use it in GitHub Desktop.
XmlMetadataSource source = XmlMetadataSource.FromAssemblyResource("Northwind.rlinq");
var model = source.GetModel();
var productType = model.PersistentTypes.FirstOrDefault(x => x.Name == "Product");
productType.OptimisticConcurrencyControlStrategy = OptimisticConcurrencyControlStrategy.Timestamp;
//Making sure there is no cached database.
Database.Get("NorthwindEntityDiagrams", new BackendConfiguration() { Backend = "mssql" }, model).Dispose();
//initialize the database with the modified metadata
Database.Get("NorthwindEntityDiagrams", new BackendConfiguration() { Backend = "mssql" }, model);
//Now create a normal context, because there already is a cached database instance with the modified metadata, one would not be created.;
using (NorthwindEntityDiagrams context = new NorthwindEntityDiagrams())
{
Console.WriteLine(context.Categories.First().CategoryName);
}
//Disposing the database object so that the next call uses the correct metadata.
Database.Get("NorthwindEntityDiagrams", new BackendConfiguration() { Backend = "mssql" }, model).Dispose();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment