예제 #1
0
        private IServiceProvider CreateServices(SqlDbTypes sqlDbOptions, string dbConnectionString, Assembly[] assemblies)
        {
            var serviceCollection = new ServiceCollection()
                                    .AddFluentMigratorCore()
                                    .AddLogging(lb => lb.AddFluentMigratorConsole());

            switch (sqlDbOptions)
            {
            case SqlDbTypes.SqlServer:
                serviceCollection.Configure <RunnerOptions>(opt => { opt.Tags = new[] { SqlDbTypes.SqlServer.ToString() }; });
                serviceCollection.ConfigureRunner(rb =>
                {
                    rb
                    .AddSqlServer()
                    .WithGlobalConnectionString(dbConnectionString)
                    .ScanIn(assemblies).For.Migrations();

                    if (VersionTableMetaData != null)
                    {
                        rb.WithVersionTable(VersionTableMetaData);
                    }
                });
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(sqlDbOptions), sqlDbOptions, null);
            }

            return(serviceCollection.BuildServiceProvider(false));
        }
예제 #2
0
        protected SqlColumn Property <TValue>(Expression <Func <T, TValue> > expression)
        {
            SqlDbType type = SqlDbTypes.GetSqlDbType <TValue>();

            string    entityFieldName = expression.GetMemberName();
            SqlColumn column          = new SqlColumn(entityFieldName, _entityColumns.Count)
                                        .HasColumnType(type)
                                        .From <T>();

            _columns.Add(column);
            _entityColumns.Add(entityFieldName, column);

            return(column);
        }
예제 #3
0
        public TOutput ExecuteSingleOutputStoredProcedure <TOutput>(string procedureName, StoredProcedureParameterMap parameters, string outputParameterName)
        {
            using (sqlConnection)
                using (SqlCommand command = new SqlCommand(procedureName, sqlConnection))
                {
                    command.CommandType = CommandType.StoredProcedure;

                    this.AddInputParametersToCommandIfTheyAreNotNull(parameters, command);
                    command.Parameters.Add(outputParameterName, SqlDbTypes.Of(typeof(TOutput))).Direction = ParameterDirection.Output;

                    OpenConnection();

                    try
                    {
                        command.ExecuteNonQuery();
                        return((TOutput)command.Parameters[outputParameterName].Value);
                    }
                    catch (SqlException e)
                    {
                        throw new StoredProcedureException(e.Message, e);
                    }
                }
        }
예제 #4
0
        public static void GetSqlDbType_NullableDateTime()
        {
            SqlDbType type = SqlDbTypes.GetSqlDbType<DateTime?>();

            Assert.AreEqual(SqlDbType.DateTime, type);
        }