-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathFamilyDbContext.cs
45 lines (42 loc) · 1.73 KB
/
FamilyDbContext.cs
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
using System;
using System.Data.Entity;
using TrackableEntities.EF.Tests.FamilyModels;
namespace TrackableEntities.EF.Tests.Contexts
{
public class FamilyDbContext : DbContext
{
#if EF_6
private const string TestDbName = "FamilyTestDbv6";
#else
private const string TestDbName = "FamilyTestDbv5";
#endif
public FamilyDbContext(CreateDbOptions createDbOptions = CreateDbOptions.CreateDatabaseIfNotExists)
: base(TestDbName)
{
switch (createDbOptions)
{
case CreateDbOptions.DropCreateDatabaseAlways:
Database.SetInitializer(new DropCreateDatabaseAlways<FamilyDbContext>());
break;
case CreateDbOptions.DropCreateDatabaseSeed:
throw new NotSupportedException("DropCreateDatabaseSeed not supported");
case CreateDbOptions.DropCreateDatabaseIfModelChanges:
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<FamilyDbContext>());
break;
default:
Database.SetInitializer(new CreateDatabaseIfNotExists<FamilyDbContext>());
break;
}
}
public DbSet<Parent> Parents { get; set; }
public DbSet<Child> Children { get; set; }
public DbSet<Contact> Contacts { get; set; }
public DbSet<ContactCategory> ContactCategories { get; set; }
public DbSet<ContactData> ContactDatas { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Child>().Ignore(child => child.Nickname2);
}
}
}