1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace ConcurrencyModel
{
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Infrastructure;
public class F1Context : DbContext
{
static F1Context()
{
Database.SetInitializer(new ConcurrencyModelInitializer());
}
public F1Context(bool lazyLoadingEnabled = true, bool proxyCreationEnabled = true)
{
SetContextOptions(lazyLoadingEnabled, proxyCreationEnabled);
}
public F1Context(DbCompiledModel model, bool lazyLoadingEnabled = true, bool proxyCreationEnabled = true)
: base(model)
{
SetContextOptions(lazyLoadingEnabled, proxyCreationEnabled);
}
public F1Context(string nameOrConnectionString, bool lazyLoadingEnabled = true, bool proxyCreationEnabled = true)
: base(nameOrConnectionString)
{
SetContextOptions(lazyLoadingEnabled, proxyCreationEnabled);
}
public F1Context(
string nameOrConnectionString, DbCompiledModel model, bool lazyLoadingEnabled = true, bool proxyCreationEnabled = true)
: base(nameOrConnectionString, model)
{
SetContextOptions(lazyLoadingEnabled, proxyCreationEnabled);
}
public F1Context(
DbConnection existingConnection, bool contextOwnsConnection, bool lazyLoadingEnabled = true, bool proxyCreationEnabled = true)
: base(existingConnection, contextOwnsConnection)
{
SetContextOptions(lazyLoadingEnabled, proxyCreationEnabled);
}
public F1Context(
DbConnection existingConnection, DbCompiledModel model, bool contextOwnsConnection, bool lazyLoadingEnabled = true,
bool proxyCreationEnabled = true)
: base(existingConnection, model, contextOwnsConnection)
{
SetContextOptions(lazyLoadingEnabled, proxyCreationEnabled);
}
public F1Context(
ObjectContext objectContext, bool dbContextOwnsObjectContext, bool lazyLoadingEnabled = true, bool proxyCreationEnabled = true)
: base(objectContext, dbContextOwnsObjectContext)
{
SetContextOptions(lazyLoadingEnabled, proxyCreationEnabled);
}
private void SetContextOptions(bool lazyLoadingEnabled, bool proxyCreationEnabled)
{
// Only change the flags if set to false so that the tests can test that the defaults are true.
if (!lazyLoadingEnabled)
{
Configuration.LazyLoadingEnabled = false;
}
if (!proxyCreationEnabled)
{
Configuration.ProxyCreationEnabled = false;
}
}
public DbSet<Team> Teams { get; set; }
public DbSet<Driver> Drivers { get; set; }
public DbSet<Sponsor> Sponsors { get; set; }
public DbSet<Engine> Engines { get; set; }
public DbSet<EngineSupplier> EngineSuppliers { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
AdditionalModelConfiguration(modelBuilder);
}
public static void AdditionalModelConfiguration(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Chassis>().HasRequired(c => c.Team).WithRequiredDependent(t => t.Chassis).WillCascadeOnDelete();
modelBuilder.ComplexType<Location>();
modelBuilder.Entity<Sponsor>().ToTable("Sponsors");
modelBuilder.Entity<TitleSponsor>().ToTable("TitleSponsors");
}
}
}
|