protected RelationalConnection([NotNull] DbContextService <IDbContextOptions> options, [NotNull] ILoggerFactory loggerFactory) : base(loggerFactory) { Check.NotNull(options, "options"); var storeConfig = RelationalOptionsExtension.Extract(options.Service); if (storeConfig.Connection != null) { if (!string.IsNullOrWhiteSpace(storeConfig.ConnectionString)) { throw new InvalidOperationException(Strings.ConnectionAndConnectionString); } _connection = new LazyRef <DbConnection>(() => storeConfig.Connection); _connectionOwned = false; _openedCount = storeConfig.Connection.State == ConnectionState.Open ? 1 : 0; } else if (!string.IsNullOrWhiteSpace(storeConfig.ConnectionString)) { _connectionString = storeConfig.ConnectionString; _connection = new LazyRef <DbConnection>(CreateDbConnection); _connectionOwned = true; } else { throw new InvalidOperationException(Strings.NoConnectionOrConnectionString); } }
public async Task TestSaveChangesAsync() { var saveAction = new SampleSaveAction(); var context = new SampleDbContext(); var service = new DbContextService <SampleDbContext>(context, new List <ISaveAction> { saveAction }); Assert.AreEqual(0, saveAction.BeforeSaveChangesCount); Assert.AreEqual(0, saveAction.AfterSaveChangesCount); Assert.AreEqual(0, saveAction.BeforeSaveChangesCountAsync); Assert.AreEqual(0, saveAction.AfterSaveChangesCountAsync); Assert.IsFalse(context.SaveChangesCalled); Assert.IsFalse(context.SaveChangesAsyncCalled); await service.SaveChangesAsync(); Assert.AreEqual(0, saveAction.BeforeSaveChangesCount); Assert.AreEqual(0, saveAction.AfterSaveChangesCount); Assert.AreEqual(1, saveAction.BeforeSaveChangesCountAsync); Assert.AreEqual(1, saveAction.AfterSaveChangesCountAsync); Assert.IsFalse(context.SaveChangesCalled); Assert.IsTrue(context.SaveChangesAsyncCalled); Assert.IsTrue(context == saveAction.GivenContext); }
public async Task <IActionResult> Firm([FromRoute] string culture) { FırmViewModel firmViewModel = null; try { // StaticData staticData = await lawyerDbContext.StaticDatas?.SingleOrDefaultAsync(); int?languageId = DbContextService.GetLanguageIdByShortName(lawyerDbContext, culture); if (languageId == null) { return(NotFound()); } var firm = (await lawyerDbContext.GetFirmViewAsync()).SingleOrDefault(m => m.LanguageId == languageId); firmViewModel = new FırmViewModel { Title = firm?.Title, Description = firm?.Description, Img = firm?.Img }; } catch { return(NotFound()); } return(View(firmViewModel)); }
public async Task <IActionResult> Index([FromRoute] string culture) { IndexViewModel indexViewModel = null; try { int?languageId = DbContextService.GetLanguageIdByShortName(lawyerDbContext, culture); if (languageId == null) { return(NotFound()); } indexViewModel = new IndexViewModel { Sliders = await lawyerDbContext.Sliders.ToListAsync(), Areas = (await lawyerDbContext.GetAreaViewAsync()) .Where(m => m.LanguageId == languageId) .ToList(), Contact = (await lawyerDbContext.GetContactViewAsync()) .SingleOrDefault(m => m.LanguageId == languageId), TeamService = (await lawyerDbContext.GetTeamServicesViewAsync()) .SingleOrDefault(m => m.LanguageId == languageId) }; } catch { return(NotFound()); } return(View(indexViewModel)); }
public InMemoryDataStore( [NotNull] StateManager stateManager, [NotNull] DbContextService <IModel> model, [NotNull] EntityKeyFactorySource entityKeyFactorySource, [NotNull] EntityMaterializerSource entityMaterializerSource, [NotNull] ClrCollectionAccessorSource collectionAccessorSource, [NotNull] ClrPropertySetterSource propertySetterSource, [NotNull] InMemoryDatabase persistentDatabase, [NotNull] DbContextService <IDbContextOptions> options, [NotNull] ILoggerFactory loggerFactory) : base(stateManager, model, entityKeyFactorySource, entityMaterializerSource, collectionAccessorSource, propertySetterSource, loggerFactory) { Check.NotNull(persistentDatabase, "persistentDatabase"); var storeConfig = options.Service.Extensions .OfType <InMemoryOptionsExtension>() .FirstOrDefault(); _persist = (storeConfig != null ? (bool?)storeConfig.Persist : null) ?? true; _database = new ThreadSafeLazyRef <InMemoryDatabase>( () => _persist ? persistentDatabase : new InMemoryDatabase(loggerFactory)); }
public async Task <IActionResult> Contact([FromRoute] string culture) { int?languageId = DbContextService.GetLanguageIdByShortName(lawyerDbContext, culture); if (languageId == null) { return(NotFound()); } try { var contact = (await lawyerDbContext.GetContactViewAsync()).SingleOrDefault(m => m.LanguageId == languageId); ContactsViewModel contactsViewModel = new ContactsViewModel { Email = contact?.ContactEmail, Number = contact?.ContactNumber, Address = contact?.ContactAdress }; return(View(contactsViewModel)); } catch { return(NotFound()); } }
public virtual async Task <object> NextAsync( IProperty property, DbContextService <DataStoreServices> dataStoreServices, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(property, "property"); Check.NotNull(dataStoreServices, "dataStoreServices"); var newValue = GetNextValue(); // If the chosen value is outside of the current block then we need a new block. // It is possible that other threads will use all of the new block before this thread // gets a chance to use the new new value, so use a while here to do it all again. while (newValue.Current >= newValue.Max) { // Once inside the lock check to see if another thread already got a new block, in which // case just get a value out of the new block instead of requesting one. using (await _lock.LockAsync(cancellationToken).WithCurrentCulture()) { if (newValue.Max == _currentValue.Max) { var newCurrent = await GetNewCurrentValueAsync(property, dataStoreServices, cancellationToken); newValue = new SequenceValue(newCurrent, newCurrent + BlockSize); _currentValue = newValue; } else { newValue = GetNextValue(); } } } return(Convert.ChangeType(newValue.Current, property.PropertyType.UnwrapNullableType())); }
public async Task <IActionResult> Index() { int?languageId = DbContextService.GetLanguageIdByShortName(lawyerDbContext); IEnumerable <TeamMemberDto> teamMemberViews = await lawyerDbContext.GetTeamMembersViewAsync(); return(View(teamMemberViews.Where(m => m.LanguageId == languageId))); }
public async Task <IActionResult> Index() { IEnumerable <ContactDto> ContatViews = (await lawyerDbContext.GetContactViewAsync()) .Where(m => m.LanguageId == DbContextService.GetLanguageIdByShortName(lawyerDbContext)); return(View(ContatViews)); }
public async Task <IActionResult> Details([Required][FromRoute] int id) { if (ModelState.IsValid) { try { TeamMemberDetailModel teamMembeDetailModel = new TeamMemberDetailModel(); teamMembeDetailModel.TeamMemberViews = (await lawyerDbContext.GetTeamMembersViewAsync()) .Where(m => m.Id == id) ?.OrderBy(m => m.LanguageId); teamMembeDetailModel.Languages = await lawyerDbContext.Languages .AsNoTracking() .ToListAsync(); string areaNameKey = lawyerDbContext.TeamToAreas.Include <TeamToArea>("Area") .FirstOrDefault(m => m.TeamMemberId == id) ?.Area.NameKey; teamMembeDetailModel.Area = lawyerDbContext.Texts .SingleOrDefault(m => m.Key == areaNameKey && m.LanguageId == DbContextService.GetLanguageIdByShortName(lawyerDbContext, "en-US")) ?.TextContent; return(View(teamMembeDetailModel)); } catch { } } return(RedirectToAction(nameof(Index))); }
public ConsoleAdaptor(IValidate validator) { Validator = validator; User = new User(); _dbContext = new DbContextService(); //StartOperation(); }
public SqlServerBatchExecutor( [NotNull] SqlServerTypeMapper typeMapper, [NotNull] DbContextService <DbContext> context, [NotNull] ILoggerFactory loggerFactory) : base(typeMapper, context, loggerFactory) { }
public virtual GeneratedValue Next(IProperty property, DbContextService <DataStoreServices> dataStoreServices) { Check.NotNull(property, "property"); Check.NotNull(dataStoreServices, "dataStoreServices"); var newValue = GetNextValue(); // If the chosen value is outside of the current block then we need a new block. // It is possible that other threads will use all of the new block before this thread // gets a chance to use the new new value, so use a while here to do it all again. while (newValue.Current >= newValue.Max) { using (_lock.Lock()) { // Once inside the lock check to see if another thread already got a new block, in which // case just get a value out of the new block instead of requesting one. if (newValue.Max == _currentValue.Max) { var newCurrent = GetNewCurrentValue(property, dataStoreServices); newValue = new SequenceValue(newCurrent, newCurrent + _blockSize); _currentValue = newValue; } else { newValue = GetNextValue(); } } } return(new GeneratedValue(Convert.ChangeType(newValue.Current, property.PropertyType.UnwrapNullableType()))); }
protected RelationalDataStore( [NotNull] StateManager stateManager, [NotNull] DbContextService <IModel> model, [NotNull] EntityKeyFactorySource entityKeyFactorySource, [NotNull] EntityMaterializerSource entityMaterializerSource, [NotNull] ClrCollectionAccessorSource collectionAccessorSource, [NotNull] ClrPropertySetterSource propertySetterSource, [NotNull] RelationalConnection connection, [NotNull] CommandBatchPreparer batchPreparer, [NotNull] BatchExecutor batchExecutor, [NotNull] DbContextService <IDbContextOptions> options, [NotNull] ILoggerFactory loggerFactory) : base(stateManager, model, entityKeyFactorySource, entityMaterializerSource, collectionAccessorSource, propertySetterSource, loggerFactory) { Check.NotNull(connection, "connection"); Check.NotNull(batchPreparer, "batchPreparer"); Check.NotNull(batchExecutor, "batchExecutor"); Check.NotNull(options, "options"); _batchPreparer = batchPreparer; _batchExecutor = batchExecutor; _connection = connection; _options = options.Service; }
public Migrator( [NotNull] HistoryRepository historyRepository, [NotNull] MigrationAssembly migrationAssembly, [NotNull] ModelDiffer modelDiffer, [NotNull] IMigrationOperationSqlGeneratorFactory ddlSqlGeneratorFactory, [NotNull] SqlGenerator dmlSqlGenerator, [NotNull] SqlStatementExecutor sqlExecutor, [NotNull] RelationalDataStoreCreator storeCreator, [NotNull] RelationalConnection connection, [NotNull] ILoggerFactory loggerFactory) { Check.NotNull(historyRepository, "historyRepository"); Check.NotNull(migrationAssembly, "migrationAssembly"); Check.NotNull(modelDiffer, "modelDiffer"); Check.NotNull(ddlSqlGeneratorFactory, "ddlSqlGeneratorFactory"); Check.NotNull(dmlSqlGenerator, "dmlSqlGenerator"); Check.NotNull(sqlExecutor, "sqlExecutor"); Check.NotNull(storeCreator, "storeCreator"); Check.NotNull(connection, "connection"); Check.NotNull(loggerFactory, "loggerFactory"); _historyRepository = historyRepository; _migrationAssembly = migrationAssembly; _modelDiffer = modelDiffer; _ddlSqlGeneratorFactory = ddlSqlGeneratorFactory; _dmlSqlGenerator = dmlSqlGenerator; _sqlExecutor = sqlExecutor; _storeCreator = storeCreator; _connection = connection; _logger = new DbContextService <ILogger>(loggerFactory.Create <Migrator>); }
public async Task <IActionResult> Index() { IEnumerable <FirmDto> firmViews = (await lawyerDbContext.GetFirmViewAsync()) .Where(m => m.LanguageId == DbContextService.GetLanguageIdByShortName(lawyerDbContext)).ToList(); return(View(firmViews)); }
public StateManager( [NotNull] StateEntryFactory factory, [NotNull] EntityKeyFactorySource entityKeyFactorySource, [NotNull] StateEntrySubscriber subscriber, [NotNull] StateEntryNotifier notifier, [NotNull] ValueGenerationManager valueGeneration, [NotNull] DbContextService <IModel> model, [NotNull] DbContextService <DataStore> dataStore) { Check.NotNull(factory, "factory"); Check.NotNull(entityKeyFactorySource, "entityKeyFactorySource"); Check.NotNull(subscriber, "subscriber"); Check.NotNull(notifier, "notifier"); Check.NotNull(model, "model"); Check.NotNull(dataStore, "dataStore"); Check.NotNull(valueGeneration, "valueGeneration"); _keyFactorySource = entityKeyFactorySource; _factory = factory; _subscriber = subscriber; _notifier = notifier; _valueGeneration = valueGeneration; _model = model; _dataStore = dataStore; }
protected DataStore( [NotNull] StateManager stateManager, [NotNull] DbContextService <IModel> model, [NotNull] EntityKeyFactorySource entityKeyFactorySource, [NotNull] EntityMaterializerSource entityMaterializerSource, [NotNull] ClrCollectionAccessorSource collectionAccessorSource, [NotNull] ClrPropertySetterSource propertySetterSource, [NotNull] ILoggerFactory loggerFactory) { Check.NotNull(stateManager, "stateManager"); Check.NotNull(model, "model"); Check.NotNull(entityKeyFactorySource, "entityKeyFactorySource"); Check.NotNull(entityMaterializerSource, "entityMaterializerSource"); Check.NotNull(collectionAccessorSource, "collectionAccessorSource"); Check.NotNull(propertySetterSource, "propertySetterSource"); Check.NotNull(loggerFactory, "loggerFactory"); _stateManager = stateManager; _model = model; _entityKeyFactorySource = entityKeyFactorySource; _entityMaterializerSource = entityMaterializerSource; _collectionAccessorSource = collectionAccessorSource; _propertySetterSource = propertySetterSource; _logger = new LazyRef <ILogger>(loggerFactory.Create <DataStore>); }
public MigrationAssembly([NotNull] DbContextService <DbContext> context, [NotNull] DbContextService <IDbContextOptions> options) { Check.NotNull(context, "context"); Check.NotNull(options, "options"); _context = context; _options = options; }
protected DataStoreSource([NotNull] DbContextServices services, [NotNull] DbContextService <IDbContextOptions> options) { Check.NotNull(services, "services"); Check.NotNull(options, "options"); _services = services; _options = options; }
public InMemoryDatabaseFacade( [NotNull] DbContextService <IModel> model, [NotNull] InMemoryDataStoreCreator dataStoreCreator, [NotNull] InMemoryConnection connection, [NotNull] ILoggerFactory loggerFactory) : base(model, dataStoreCreator, connection, loggerFactory) { }
protected RelationalDatabase( [NotNull] DbContextService <IModel> model, [NotNull] DataStoreCreator dataStoreCreator, [NotNull] DataStoreConnection connection, [NotNull] ILoggerFactory loggerFactory) : base(model, dataStoreCreator, connection, loggerFactory) { }
public ConcreteDatabase( DbContextService <IModel> model, DataStoreCreator dataStoreCreator, DataStoreConnection connection, ILoggerFactory loggerFactory) : base(model, dataStoreCreator, connection, loggerFactory) { }
public async Task TestSaveChangesAsync_NoActions() { var context = new SampleDbContext(); var service = new DbContextService <SampleDbContext>(context); await service.SaveChangesAsync(); Assert.IsFalse(context.SaveChangesCalled); Assert.IsTrue(context.SaveChangesAsyncCalled); }
public virtual Task <GeneratedValue> NextAsync( IProperty property, DbContextService <DataStoreServices> dataStoreServices, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(property, "property"); return(Task.FromResult(Next(property))); }
/// <inheritdoc> public virtual TModel Find(object[] key) { using (var ctx = DbContextService.CreateContext()) { var dbSet = ctx.Set(typeof(TEntity)); var entity = dbSet.Find(key); if (entity == null) { return(default);
public SqlServerDatabase( [NotNull] DbContextService <IModel> model, [NotNull] SqlServerDataStoreCreator dataStoreCreator, [NotNull] SqlServerConnection connection, [NotNull] SqlServerMigrator migrator, [NotNull] ILoggerFactory loggerFactory) : base(model, dataStoreCreator, connection, migrator, loggerFactory) { }
public void TestSaveChanges_NoActions() { var context = new SampleDbContext(); var service = new DbContextService <SampleDbContext>(context); service.SaveChanges(); Assert.IsTrue(context.SaveChangesCalled); Assert.IsFalse(context.SaveChangesAsyncCalled); }
public ConcreteMigrationsEnabledDatabase( DbContextService <IModel> model, DataStoreCreator dataStoreCreator, DataStoreConnection connection, Migrator migrator, ILoggerFactory loggerFactory) : base(model, dataStoreCreator, connection, migrator, loggerFactory) { }
public FakeDatabase( DbContextService <IModel> model, RecordingDataStoreCreator dataStoreCreator, FakeRelationalConnection connection, TestMigrator migrator, ILoggerFactory loggerFactory) : base(model, dataStoreCreator, connection, migrator, loggerFactory) { }