public SqlServerConnection([NotNull] IEntityOptions options, [NotNull] ILoggerFactory loggerFactory) : base(options, loggerFactory) { Check.NotNull(loggerFactory, nameof(loggerFactory)); _loggerFactory = loggerFactory; }
protected RelationalDataStore( [NotNull] IModel model, [NotNull] IEntityKeyFactorySource entityKeyFactorySource, [NotNull] IEntityMaterializerSource entityMaterializerSource, [NotNull] IClrAccessorSource <IClrPropertyGetter> clrPropertyGetterSource, [NotNull] IRelationalConnection connection, [NotNull] ICommandBatchPreparer batchPreparer, [NotNull] IBatchExecutor batchExecutor, [NotNull] IEntityOptions options, [NotNull] ILoggerFactory loggerFactory, [NotNull] IRelationalValueBufferFactoryFactory valueBufferFactoryFactory) : base( Check.NotNull(model, nameof(model)), Check.NotNull(entityKeyFactorySource, nameof(entityKeyFactorySource)), Check.NotNull(entityMaterializerSource, nameof(entityMaterializerSource)), Check.NotNull(clrPropertyGetterSource, nameof(clrPropertyGetterSource)), Check.NotNull(loggerFactory, nameof(loggerFactory))) { Check.NotNull(connection, nameof(connection)); Check.NotNull(batchPreparer, nameof(batchPreparer)); Check.NotNull(batchExecutor, nameof(batchExecutor)); Check.NotNull(options, nameof(options)); Check.NotNull(options, nameof(options)); Check.NotNull(valueBufferFactoryFactory, nameof(valueBufferFactoryFactory)); _batchPreparer = batchPreparer; _batchExecutor = batchExecutor; _connection = connection; _options = options; ValueBufferFactoryFactory = valueBufferFactoryFactory; }
public InMemoryDataStore( [NotNull] IModel model, [NotNull] IEntityKeyFactorySource entityKeyFactorySource, [NotNull] IEntityMaterializerSource entityMaterializerSource, [NotNull] IClrAccessorSource <IClrPropertyGetter> clrPropertyGetterSource, [NotNull] IInMemoryDatabase persistentDatabase, [NotNull] IEntityOptions options, [NotNull] ILoggerFactory loggerFactory) : base( Check.NotNull(model, nameof(model)), Check.NotNull(entityKeyFactorySource, nameof(entityKeyFactorySource)), Check.NotNull(entityMaterializerSource, nameof(entityMaterializerSource)), Check.NotNull(clrPropertyGetterSource, nameof(clrPropertyGetterSource)), Check.NotNull(loggerFactory, nameof(loggerFactory))) { Check.NotNull(persistentDatabase, nameof(persistentDatabase)); var storeConfig = options.Extensions .OfType <InMemoryOptionsExtension>() .FirstOrDefault(); _persist = storeConfig?.Persist ?? true; _database = new ThreadSafeLazyRef <IInMemoryDatabase>( () => _persist ? persistentDatabase : new InMemoryDatabase(loggerFactory)); }
public DataStoreSelector( [NotNull] IServiceProvider serviceProvider, [NotNull] IEntityOptions contextOptions, [CanBeNull] IEnumerable <IDataStoreSource> sources) { Check.NotNull(serviceProvider, nameof(serviceProvider)); Check.NotNull(contextOptions, nameof(contextOptions)); _serviceProvider = serviceProvider; _contextOptions = contextOptions; _sources = sources == null ? new IDataStoreSource[0] : sources.ToArray(); }
public DataStoreSelector( [NotNull] IServiceProvider serviceProvider, [NotNull] IEntityOptions contextOptions, [CanBeNull] IEnumerable<IDataStoreSource> sources) { Check.NotNull(serviceProvider, nameof(serviceProvider)); Check.NotNull(contextOptions, nameof(contextOptions)); _serviceProvider = serviceProvider; _contextOptions = contextOptions; _sources = sources == null ? new IDataStoreSource[0] : sources.ToArray(); }
public override ModificationCommandBatch Create( IEntityOptions options, IRelationalMetadataExtensionProvider metadataExtensionProvider) { var optionsExtension = options.Extensions.OfType <SqlServerOptionsExtension>().FirstOrDefault(); var maxBatchSize = optionsExtension?.MaxBatchSize; return(new TestSqlServerModificationCommandBatch( (ISqlServerSqlGenerator)SqlGenerator, metadataExtensionProvider, maxBatchSize)); }
public override ModificationCommandBatch Create( IEntityOptions options, IRelationalMetadataExtensionProvider metadataExtensionProvider) { Check.NotNull(options, nameof(options)); Check.NotNull(metadataExtensionProvider, nameof(metadataExtensionProvider)); var optionsExtension = options.Extensions.OfType<SqlServerOptionsExtension>().FirstOrDefault(); var maxBatchSize = optionsExtension?.MaxBatchSize; return new SqlServerModificationCommandBatch( (ISqlServerSqlGenerator)SqlGenerator, metadataExtensionProvider, maxBatchSize); }
public virtual IServiceProvider GetOrAdd(IEntityOptions options) { var services = new ServiceCollection(); var builder = services.AddEntityFramework(); foreach (var extension in options.Extensions) { extension.ApplyServices(builder); } // Decided that this hashing algorithm is robust enough. See issue #762. unchecked { var key = services.Aggregate(0, (t, d) => (t * 397) ^ CalculateHash(d).GetHashCode()); return(_configurations.GetOrAdd(key, k => services.BuildServiceProvider())); } }
public virtual IServiceProvider GetOrAdd(IEntityOptions options) { var services = new ServiceCollection(); var builder = services.AddEntityFramework(); foreach (var extension in options.Extensions) { extension.ApplyServices(builder); } // Decided that this hashing algorithm is robust enough. See issue #762. unchecked { var key = services.Aggregate(0, (t, d) => (t * 397) ^ CalculateHash(d).GetHashCode()); return _configurations.GetOrAdd(key, k => services.BuildServiceProvider()); } }
public static RelationalOptionsExtension Extract([NotNull] IEntityOptions options) { Check.NotNull(options, nameof(options)); var storeConfigs = options.Extensions .OfType <RelationalOptionsExtension>() .ToArray(); if (storeConfigs.Length == 0) { throw new InvalidOperationException(Strings.NoDataStoreConfigured); } if (storeConfigs.Length > 1) { throw new InvalidOperationException(Strings.MultipleDataStoresConfigured); } return(storeConfigs[0]); }
public MigrationAssembly( [NotNull] DbContext context, [NotNull] IEntityOptions options, [NotNull] IMigrationModelFactory modelFactory) { Check.NotNull(context, nameof(context)); Check.NotNull(options, nameof(options)); Check.NotNull(modelFactory, nameof(modelFactory)); var contextType = context.GetType(); var assemblyName = RelationalOptionsExtension.Extract(options)?.MigrationsAssembly; var assembly = assemblyName == null ? contextType.GetTypeInfo().Assembly : Assembly.Load(new AssemblyName(assemblyName)); _migrations = new LazyRef <IReadOnlyList <Migration> >( () => GetMigrationTypes(assembly) .Where(t => TryGetContextType(t) == contextType) .Select(t => (Migration)Activator.CreateInstance(t.AsType())) .OrderBy(m => m.Id) .ToList()); _modelSnapshot = new LazyRef <ModelSnapshot>( () => ( from t in GetTypes(assembly) where t.IsSubclassOf(typeof(ModelSnapshot)) && TryGetContextType(t) == contextType select(ModelSnapshot) Activator.CreateInstance(t.AsType())) .FirstOrDefault()); _lastModel = new LazyRef <IModel>( () => { if (_modelSnapshot.Value == null) { return(null); } return(modelFactory.CreateModel(_modelSnapshot.Value.BuildModel)); }); }
public virtual IDbContextServices Initialize( IServiceProvider scopedProvider, IEntityOptions contextOptions, DbContext context, ServiceProviderSource serviceProviderSource) { Check.NotNull(scopedProvider, nameof(scopedProvider)); Check.NotNull(contextOptions, nameof(contextOptions)); Check.NotNull(context, nameof(context)); Check.IsDefined(serviceProviderSource, nameof(serviceProviderSource)); _provider = scopedProvider; _contextOptions = contextOptions; _context = context; _dataStoreServices = new LazyRef<IDataStoreServices>(() => _provider.GetRequiredService<IDataStoreSelector>().SelectDataStore(serviceProviderSource)); _modelFromSource = new LazyRef<IModel>(CreateModel); return this; }
public virtual IDbContextServices Initialize( IServiceProvider scopedProvider, IEntityOptions contextOptions, DbContext context, ServiceProviderSource serviceProviderSource) { Check.NotNull(scopedProvider, nameof(scopedProvider)); Check.NotNull(contextOptions, nameof(contextOptions)); Check.NotNull(context, nameof(context)); Check.IsDefined(serviceProviderSource, nameof(serviceProviderSource)); _provider = scopedProvider; _contextOptions = contextOptions; _context = context; _dataStoreServices = new LazyRef <IDataStoreServices>(() => _provider.GetRequiredService <IDataStoreSelector>().SelectDataStore(serviceProviderSource)); _modelFromSource = new LazyRef <IModel>(CreateModel); return(this); }
protected RelationalConnection([NotNull] IEntityOptions options, [NotNull] ILoggerFactory loggerFactory) { Check.NotNull(options, nameof(options)); Check.NotNull(loggerFactory, nameof(loggerFactory)); _logger = new LazyRef <ILogger>(loggerFactory.CreateLogger <RelationalConnection>); var storeConfig = RelationalOptionsExtension.Extract(options); _commandTimeout = storeConfig.CommandTimeout; 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); } #if NET45 _throwOnAmbientTransaction = storeConfig.ThrowOnAmbientTransaction ?? true; #endif }
public SqlServerDataStore( [NotNull] IModel model, [NotNull] IEntityKeyFactorySource entityKeyFactorySource, [NotNull] IEntityMaterializerSource entityMaterializerSource, [NotNull] IClrAccessorSource <IClrPropertyGetter> clrPropertyGetterSource, [NotNull] ISqlServerConnection connection, [NotNull] ICommandBatchPreparer batchPreparer, [NotNull] IBatchExecutor batchExecutor, [NotNull] IEntityOptions options, [NotNull] ILoggerFactory loggerFactory, [NotNull] IRelationalValueBufferFactoryFactory valueBufferFactoryFactory) : base( Check.NotNull(model, nameof(model)), Check.NotNull(entityKeyFactorySource, nameof(entityKeyFactorySource)), Check.NotNull(entityMaterializerSource, nameof(entityMaterializerSource)), Check.NotNull(clrPropertyGetterSource, nameof(clrPropertyGetterSource)), Check.NotNull(connection, nameof(connection)), Check.NotNull(batchPreparer, nameof(batchPreparer)), Check.NotNull(batchExecutor, nameof(batchExecutor)), Check.NotNull(options, nameof(options)), Check.NotNull(loggerFactory, nameof(loggerFactory)), Check.NotNull(valueBufferFactoryFactory, nameof(valueBufferFactoryFactory))) { }
public FakeRelationalDataStore( IModel model, IEntityKeyFactorySource entityKeyFactorySource, IEntityMaterializerSource entityMaterializerSource, IClrAccessorSource <IClrPropertyGetter> clrPropertyGetterSource, IRelationalConnection connection, ICommandBatchPreparer batchPreparer, IBatchExecutor batchExecutor, IEntityOptions options, ILoggerFactory loggerFactory, IRelationalValueBufferFactoryFactory valueBufferFactoryFactory) : base( model, entityKeyFactorySource, entityMaterializerSource, clrPropertyGetterSource, connection, batchPreparer, batchExecutor, options, loggerFactory, valueBufferFactoryFactory) { }
public FakeRelationalDataStore( IModel model, IEntityKeyFactorySource entityKeyFactorySource, IEntityMaterializerSource entityMaterializerSource, IClrAccessorSource<IClrPropertyGetter> clrPropertyGetterSource, IRelationalConnection connection, ICommandBatchPreparer batchPreparer, IBatchExecutor batchExecutor, IEntityOptions options, ILoggerFactory loggerFactory, IRelationalValueBufferFactoryFactory valueBufferFactoryFactory) : base( model, entityKeyFactorySource, entityMaterializerSource, clrPropertyGetterSource, connection, batchPreparer, batchExecutor, options, loggerFactory, valueBufferFactoryFactory) { }
public SqliteDataStore( [NotNull] IModel model, [NotNull] IEntityKeyFactorySource entityKeyFactorySource, [NotNull] IEntityMaterializerSource entityMaterializerSource, [NotNull] IClrAccessorSource <IClrPropertyGetter> clrPropertyGetterSource, [NotNull] IRelationalConnection connection, [NotNull] ICommandBatchPreparer batchPreparer, [NotNull] IBatchExecutor batchExecutor, [NotNull] IEntityOptions options, [NotNull] ILoggerFactory loggerFactory, [NotNull] IRelationalValueBufferFactoryFactory valueBufferFactoryFactory) : base( model, entityKeyFactorySource, entityMaterializerSource, clrPropertyGetterSource, connection, batchPreparer, batchExecutor, options, loggerFactory, valueBufferFactoryFactory) { }
public FakeConnection(IEntityOptions options) : base(options, new LoggerFactory()) { }
public override ModificationCommandBatch Create( IEntityOptions options, IRelationalMetadataExtensionProvider metadataExtensionProvider) { return(new SingularModificationCommandBatch(SqlGenerator, metadataExtensionProvider)); }
public abstract ModificationCommandBatch Create( IEntityOptions options, IRelationalMetadataExtensionProvider metadataExtensionProvider);
public FakeSqlServerConnection(IEntityOptions options, ILoggerFactory loggerFactory) : base(options, loggerFactory) { }
public virtual IEnumerable <ModificationCommandBatch> BatchCommands(IReadOnlyList <InternalEntityEntry> entries, IEntityOptions options) { Check.NotNull(entries, nameof(entries)); var commands = CreateModificationCommands(entries); var sortedCommandSets = TopologicalSort(commands); // TODO: Enable batching of dependent commands by passing through the dependency graph foreach (var independentCommandSet in sortedCommandSets) { independentCommandSet.Sort(_modificationCommandComparer); var batch = _modificationCommandBatchFactory.Create(options, _metadataExtensionProvider); foreach (var modificationCommand in independentCommandSet) { if (!_modificationCommandBatchFactory.AddCommand(batch, modificationCommand)) { yield return(batch); batch = _modificationCommandBatchFactory.Create(options, _metadataExtensionProvider); _modificationCommandBatchFactory.AddCommand(batch, modificationCommand); } } yield return(batch); } }
public virtual bool IsConfigured(IEntityOptions options) { Check.NotNull(options, nameof(options)); return(options.Extensions.OfType <TOptionsExtension>().Any()); }
public override ModificationCommandBatch Create( IEntityOptions options, IRelationalMetadataExtensionProvider metadataExtensionProvider) { return new SingularModificationCommandBatch(SqlGenerator, metadataExtensionProvider); }
public SqliteDataStoreConnection([NotNull] IEntityOptions options, [NotNull] ILoggerFactory loggerFactory) : base(options, loggerFactory) { }