/// <summary>
        /// Initializes a new instance of the <see cref="FileStreamRepositoryContextBase" /> class.
        /// </summary>
        /// <param name="path">The database directory to create.</param>
        /// <param name="extension">The file extension.</param>
        /// <param name="ignoreTransactionWarning">If a transaction operation is requested, ignore any warnings since the context provider does not support transactions.</param>
        /// <param name="ignoreSqlQueryWarning">If a SQL query is executed, ignore any warnings since the in-memory provider does not support SQL query execution.</param>
        protected FileStreamRepositoryContextBase(string path, string extension, bool ignoreTransactionWarning = false, bool ignoreSqlQueryWarning = false)
        {
            Guard.NotEmpty(path, nameof(path));
            Guard.NotEmpty(extension, nameof(extension));

            if (!string.IsNullOrEmpty(Path.GetExtension(path)))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "The specified '{0}' path cannot be a file name.", path));
            }

            if (!extension.StartsWith(".") || string.IsNullOrEmpty(Path.GetExtension(extension)))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "The specified '{0}' extension is not valid.", path));
            }

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            if (!path.EndsWith(@"\"))
            {
                path += @"\";
            }

            Conventions = RepositoryConventions.Default <FileStreamRepositoryContextBase>();

            _items = new BlockingCollection <EntitySet>();
            _ignoreTransactionWarning = ignoreTransactionWarning;
            _ignoreSqlQueryWarning    = ignoreSqlQueryWarning;
            _path      = path;
            _extension = extension;
        }
Exemplo n.º 2
0
 private void ConfigureConventions()
 {
     Conventions = new RepositoryConventions(GetType())
     {
         PrimaryKeysCallback = type => AzureStorageTableConventionsHelper.GetPrimaryKeyPropertyInfos(type)
     };
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureStorageBlobRepositoryContext" /> class.
        /// </summary>
        /// <param name="nameOrConnectionString">Either the database name or a connection string.</param>
        /// <param name="container">The name of the container.</param>
        /// <param name="createIfNotExists">Creates the container if it does not exist.</param>
        public AzureStorageBlobRepositoryContext(string nameOrConnectionString, string container = null, bool createIfNotExists = false)
        {
            Guard.NotEmpty(nameOrConnectionString, nameof(nameOrConnectionString));

            Conventions = RepositoryConventions.Default <AzureStorageBlobRepositoryContext>();

            var css = GetConnectionStringSettings(nameOrConnectionString);

            var connectionString = css != null
                ? css.ConnectionString
                : nameOrConnectionString;

            var account = CloudStorageAccount.Parse(connectionString);
            var client  = account.CreateCloudBlobClient();

            if (string.IsNullOrEmpty(container))
            {
                container = GetType().Name.ToLower();
            }

            BlobContainer = client.GetContainerReference(container);

            if (createIfNotExists)
            {
                BlobContainer.CreateIfNotExists();
            }
        }
Exemplo n.º 4
0
        public EfRepositoryContext(DbContext context)
        {
            Conventions = RepositoryConventions.Default();

            _context = Guard.NotNull(context, nameof(context));
            _context.Database.Log = s => Logger?.Debug(s.TrimEnd(Environment.NewLine.ToCharArray()));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EfCoreRepositoryContext" /> class.
        /// </summary>
        /// <param name="context">The context.</param>
        public EfCoreRepositoryContext(DbContext context)
        {
            Conventions = RepositoryConventions.Default <EfCoreRepositoryContext>();

            _context = Guard.NotNull(context, nameof(context));
            _context.ConfigureLogging(s => Logger.Debug(s.TrimEnd(Environment.NewLine.ToCharArray())));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InMemoryRepositoryContext" /> class.
        /// </summary>
        /// <param name="databaseName">The name of the in-memory database. This allows the scope of the in-memory database to be controlled independently of the context.</param>
        /// <param name="ignoreTransactionWarning">If a transaction operation is requested, ignore any warnings since the in-memory provider does not support transactions.</param>
        /// <param name="ignoreSqlQueryWarning">If a SQL query is executed, ignore any warnings since the in-memory provider does not support SQL query execution.</param>
        public InMemoryRepositoryContext(string databaseName, bool ignoreTransactionWarning = false, bool ignoreSqlQueryWarning = false)
        {
            DatabaseName = string.IsNullOrEmpty(databaseName) ? DefaultDatabaseName : databaseName;
            Conventions  = RepositoryConventions.Default <InMemoryRepositoryContext>();

            _ignoreTransactionWarning = ignoreTransactionWarning;
            _ignoreSqlQueryWarning    = ignoreSqlQueryWarning;
        }
        private void ConfigureConventions(DbContext context)
        {
            var helper = new EfCoreRepositoryConventionHelper(context);

            Conventions = new RepositoryConventions()
            {
                PrimaryKeysCallback = type => helper.GetPrimaryKeyPropertyInfos(type)
            };
        }
Exemplo n.º 8
0
        /// <summary>
        /// Configures the repository options with the specified conventions.
        /// </summary>
        /// <param name="conventionsAction">The configurable conventions action.</param>
        /// <returns>The same builder instance.</returns>
        public virtual RepositoryOptionsBuilder UseConventions([NotNull] Action <IRepositoryConventions> conventionsAction)
        {
            Guard.NotNull(conventionsAction, nameof(conventionsAction));

            var conventions = new RepositoryConventions();

            conventionsAction(conventions);

            return(UseConventions(conventions));
        }
        public InMemoryRepositoryContext(string databaseName, bool ignoreTransactionWarning = false, bool ignoreSqlQueryWarning = false)
        {
            DatabaseName = string.IsNullOrEmpty(databaseName) ? DefaultDatabaseName : databaseName;
            Conventions  = RepositoryConventions.Default();

            _ignoreTransactionWarning = ignoreTransactionWarning;
            _ignoreSqlQueryWarning    = ignoreSqlQueryWarning;

            _db = InMemoryDatabasesCache.Instance.GetDatabase(databaseName);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AdoNetRepositoryContext" /> class.
        /// </summary>
        /// <param name="nameOrConnectionString">Either the database name or a connection string.</param>
        /// <param name="ensureDatabaseCreated">
        /// Ensures that the database for the context exists. If it exists, no action is taken.
        /// If it does not exist then the database and all its schema are created.
        /// If the database exists, then no effort is made to ensure it is compatible with the model for this context.
        /// </param>
        public AdoNetRepositoryContext(string nameOrConnectionString, bool ensureDatabaseCreated = false)
        {
            Guard.NotEmpty(nameOrConnectionString, nameof(nameOrConnectionString));

            Conventions = RepositoryConventions.Default <AdoNetRepositoryContext>();

            _dbHelper              = new DbHelper(Conventions, nameOrConnectionString);
            _schemaConfigHelper    = new SchemaTableConfigurationHelper(_dbHelper);
            _ensureDatabaseCreated = ensureDatabaseCreated;
            _loggerProvider        = NullLoggerProvider.Instance;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AdoNetRepositoryContext" /> class.
        /// </summary>
        /// <param name="existingConnection">The existing connection.</param>
        /// <param name="ensureDatabaseCreated">
        /// Ensures that the database for the context exists. If it exists, no action is taken.
        /// If it does not exist then the database and all its schema are created.
        /// If the database exists, then no effort is made to ensure it is compatible with the model for this context.
        /// </param>
        public AdoNetRepositoryContext(DbConnection existingConnection, bool ensureDatabaseCreated = false)
        {
            Guard.NotNull(existingConnection, nameof(existingConnection));

            Conventions = RepositoryConventions.Default <AdoNetRepositoryContext>();

            _dbHelper              = new DbHelper(Conventions, existingConnection);
            _schemaConfigHelper    = new SchemaTableConfigurationHelper(_dbHelper);
            _ensureDatabaseCreated = ensureDatabaseCreated;
            _loggerProvider        = NullLoggerProvider.Instance;
        }
Exemplo n.º 12
0
        private void ConfigureConventions(ISessionFactory sessionFactory)
        {
            var helper = new NHibernateConventionsHelper(Guard.NotNull(sessionFactory, nameof(sessionFactory)));

            Conventions = new RepositoryConventions(GetType())
            {
                PrimaryKeysCallback    = type => helper.GetPrimaryKeyPropertyInfos(type),
                ColumnNameCallback     = pi => helper.GetColumnName(pi),
                ColumnOrderCallback    = pi => helper.GetColumnOrder(pi),
                IsColumnMappedCallback = pi => helper.IsColumnMapped(pi)
            };
        }
Exemplo n.º 13
0
        public void ConfigureConventions()
        {
            var conventions = new RepositoryConventions
            {
                PrimaryKeysCallback = (type) => null
            };

            var optionsBuilder = new RepositoryOptionsBuilder()
                                 .UseInMemoryDatabase()
                                 .UseConventions(conventions);

            Assert.NotNull(optionsBuilder.Options.Conventions);

            // will fail since it cannot find a primary key due to the conventions returning null
            var ex = Assert.Throws <InvalidOperationException>(() => new Repository <Customer>(optionsBuilder.Options));

            Assert.Equal($"The instance of entity type '{typeof(Customer).FullName}' requires a primary key to be defined.", ex.Message);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LinqEnumerableRepositoryContextBase"/> class.
        /// </summary>
        protected LinqEnumerableRepositoryContextBase()
        {
            Conventions = RepositoryConventions.Default();

            _loggerProvider = NullLoggerProvider.Instance;
        }
 /// <summary>
 /// Returns the fetch strategy, or a default valued if the sequence is empty.
 /// </summary>
 /// <typeparam name="T">The type of the entity.</typeparam>
 /// <param name="source">The source.</param>
 /// <returns>The fetching strategy.</returns>
 public static IFetchQueryStrategy <T> DefaultIfFetchStrategyEmpty <T>([CanBeNull] this IFetchQueryStrategy <T> source)
 {
     return(source.DefaultIfFetchStrategyEmpty(RepositoryConventions.Default()));
 }