22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
44using System . Data . Entity ;
5- using System . Data . Entity . Infrastructure ;
65
76namespace NuGetGallery
87{
98 public class EntitiesContext
10- : DbContext , IEntitiesContext
9+ : EntityInterceptorDbContext , IEntitiesContext
1110 {
1211 static EntitiesContext ( )
1312 {
@@ -16,22 +15,22 @@ static EntitiesContext()
1615 }
1716
1817 /// <summary>
19- /// The NuGet Gallery code should usually use this constructor, in order to respect read only mode.
18+ /// This constructor is provided mainly for purposes of running migrations from Package Manager console,
19+ /// or any other scenario where a connection string will be set after the EntitiesContext is created
20+ /// (and read only mode is don't care).
2021 /// </summary>
21- public EntitiesContext ( string connectionString , bool readOnly )
22- : base ( connectionString )
22+ public EntitiesContext ( )
23+ : this ( "Gallery.SqlServer" , false ) // Use the connection string in a web.config (if one is found )
2324 {
24- ReadOnly = readOnly ;
2525 }
2626
2727 /// <summary>
28- /// This constructor is provided mainly for purposes of running migrations from Package Manager console,
29- /// or any other scenario where a connection string will be set after the EntitiesContext is created
30- /// (and read only mode is don't care).
28+ /// The NuGet Gallery code should usually use this constructor, in order to respect read only mode.
3129 /// </summary>
32- public EntitiesContext ( )
33- : base ( "Gallery.SqlServer" ) // Use the connection string in a web.config (if one is found )
30+ public EntitiesContext ( string connectionString , bool readOnly )
31+ : base ( connectionString )
3432 {
33+ ReadOnly = readOnly ;
3534 }
3635
3736 public bool ReadOnly { get ; private set ; }
@@ -63,7 +62,7 @@ public void DeleteOnCommit<T>(T entity) where T : class
6362
6463 public void SetCommandTimeout ( int ? seconds )
6564 {
66- ( ( IObjectContextAdapter ) this ) . ObjectContext . CommandTimeout = seconds ;
65+ ObjectContext . CommandTimeout = seconds ;
6766 }
6867
6968#pragma warning disable 618 // TODO: remove Package.Authors completely once prodution services definitely no longer need it
@@ -214,6 +213,5 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
214213 . HasRequired ( cp => cp . PackageRegistration ) ;
215214 }
216215#pragma warning restore 618
217-
218216 }
219217}
0 commit comments