-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDatabaseContext.cs
More file actions
62 lines (55 loc) · 2.06 KB
/
Copy pathDatabaseContext.cs
File metadata and controls
62 lines (55 loc) · 2.06 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
using NonCreative.Models;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading;
namespace NonCreative
{
public class DatabaseContext : IdentityDbContext<ApplicationUser>
{
//Use threadlocal because DatabaseContext isn't thread safe
//Plus, we know that a single object won't be on 2 threads simultaneously
//so we won't have even more errors
private static ThreadLocal<DatabaseContext> _ctx =
new ThreadLocal<DatabaseContext>(() =>
{
var result = new DatabaseContext();
result.Configuration.AutoDetectChangesEnabled = false;
return result;
});
public static DatabaseContext Shared
{
get
{
if (_ctx.Value.Disposed)
_ctx.Value = new DatabaseContext();
return _ctx.Value;
}
}
public DatabaseContext()
: base("DatabaseConnection")
{
}
public System.Data.Entity.DbSet<NonCreative.Models.WallPost> WallPosts { get; set; }
public System.Data.Entity.DbSet<NonCreative.Models.WallModel> WallModels { get; set; }
public System.Data.Entity.DbSet<NonCreative.Models.FileUploadModel> Files { get; set; }
public System.Data.Entity.DbSet<NonCreative.Models.UserWallReference> WallReferences { get; set; }
public System.Data.Entity.DbSet<NonCreative.Models.UserPostReference> PostReferences { get; set; }
public System.Data.Entity.DbSet<NonCreative.Models.WallUserReferenceModel> ModeratorReferences { get; set; }
/// <summary>
/// Releases context after request
/// </summary>
public static void Release()
{
Shared.Dispose(true);
}
public bool Disposed { get; private set; }
protected override void Dispose(bool disposing)
{
Disposed = true;
base.Dispose(disposing);
}
}
}