forked from zzzprojects/System.Linq.Dynamic.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlogContext.cs
More file actions
63 lines (55 loc) · 2.03 KB
/
BlogContext.cs
File metadata and controls
63 lines (55 loc) · 2.03 KB
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
#if EFCORE
using System.Linq.Dynamic.Core.Tests.Logging;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
#else
using System.Data.Entity;
#endif
namespace System.Linq.Dynamic.Core.Tests.Helpers.Entities
{
#if EFCORE
public class BlogContext : DbContext
{
public BlogContext(DbContextOptions options)
: base(options)
{
}
public void EnableLogging()
{
var serviceProvider = this.GetInfrastructure();
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
loggerFactory.AddProvider(new DbLoggerProvider());
}
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
}
#else
[DbConfigurationType(typeof(CodeConfig))]
public class BlogContext : DbContext
{
// http://stackoverflow.com/questions/20460357/problems-using-entity-framework-6-and-sqlite
// http://stackoverflow.com/questions/18882560/entity-framework-code-first-update-database-fails-on-create-database
public BlogContext(string nameOrConnectionString) : base(nameOrConnectionString)
{
AppDomain.CurrentDomain.SetData("DataDirectory", System.IO.Directory.GetCurrentDirectory());
}
//protected override void OnModelCreating(DbModelBuilder modelBuilder)
//{
// System.Data.Entity.SqlServer.SqlProviderServices.
// //var sqliteConnectionInitializer = new SqliteDropCreateDatabaseAlways<BlogContext>(modelBuilder);
// //Database.SetInitializer(sqliteConnectionInitializer);
//}
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
}
public class CodeConfig : DbConfiguration
{
public CodeConfig()
{
SetProviderServices("System.Data.SqlClient", System.Data.Entity.SqlServer.SqlProviderServices.Instance);
}
}
#endif
}