Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ReadonlyDbContext : MyDbContext
- {
- static ReadonlyDbContext()
- {
- Database.SetInitializer<ReadonlyDbContext>(null);
- }
- public ReadonlyDbContext()
- {
- SetConfigurationOptions();
- }
- private void SetConfigurationOptions()
- {
- Configuration.LazyLoadingEnabled = false;
- Configuration.AutoDetectChangesEnabled = false;
- Configuration.ProxyCreationEnabled = false;
- }
- public override int SaveChanges()
- {
- throw new Exception("Attempted to save using a read-only dbContext");
- }
- public override Task<int> SaveChangesAsync()
- {
- throw new Exception("Attempted to save using a read-only dbContext");
- }
- public override Task<int> SaveChangesAsync(CancellationToken cancellationToken)
- {
- throw new Exception("Attempted to save using a read-only dbContext");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement