示例#1
0
        /// <inheritdoc />
        public override void ConfigureServices(IServiceCollection services)
        {
            DbConnectionManager.RegisterAdapter(new MySqlLtsAdapter());
            DbConnectionManager.RegisterDatabaseFor <DapperFor>();

            services.AddTransient(typeof(IRepository <>), typeof(Repository <>));
            services.AddTransient(typeof(IDbRepository <>), typeof(DbRepository <>));

            base.ConfigureServices(services);

            services.UseDependencyInjection();
        }
示例#2
0
        public void Initialize()
        {
            var adapter = new MySqlLtsAdapter();

            adapter.Visitors.Add(new ConvertVisitter());

            DbConnectionManager.RegisterAdapter(adapter);
            DbConnectionManager.RegisterDatabaseFor <DapperFor>();

            if (isCompleted)
            {
                return;
            }

            var connectionString = string.Format("server={0};port=3306;user=root;password={1};database=mysql;"
                                                 , MySqlConsts.Domain
                                                 , MySqlConsts.Password);

            using (var connection = TransactionConnections.GetConnection(connectionString, adapter) ?? DispatchConnections.Instance.GetConnection(connectionString, adapter))
            {
                try
                {
                    connection.Open();

                    using (var command = connection.CreateCommand())
                    {
                        command.CommandType = System.Data.CommandType.Text;

                        var files = Directory.GetFiles("../../../Sql", "*.sql");

                        foreach (var file in files.Where(x => x.Contains("mysql")))
                        {
                            string text = File.ReadAllText(file, Encoding.UTF8);

                            command.CommandText = text;

                            command.ExecuteNonQuery();
                        }
                    }

                    isCompleted = true;
                }
                finally
                {
                    connection.Close();
                }
            }
        }
示例#3
0
        public void TestMapTo()
        {
            var config = new ConnectionConfig
            {
                ProviderName     = "SQLServer",
                ConnectionString = ""
            };

            DbConnectionManager.RegisterAdapter(new SqlServerLtsAdapter());
            DbConnectionManager.RegisterDatabaseFor <DapperFor>();

            var adapter = DbConnectionManager.Get(config.ProviderName);

            var sql = new SQL(@"select 
                replace(max(gmfmc),' ','') as gmfmc,
                max(ywrq) as wrq,
                max(kplx) as autoKp,
                replace(max(sprsjh),' ','') as sprsjh,
                replace(max(sprmc),' ','') as  skr,   
                replace(max(spryx),' ','') as spryx,
                replace(max(addtel),' ','') as gmfdzdh,
                replace(max(gmfsh),' ','') as gmfsbh,
                replace(max(kfhzh),' ','') as gmfkhhjzh,  
                max(bz) as bz,
                sum(spje) as jshj,
                max(dsddh) as ddbh,
                max(fplx) as invoiceType
                from dzfp
                where ywdjid=@requestid");

            string requestid = "201909060000050";

            //var results = provider.Query<string>(connection, sql.ToString(adapter.Settings));

            var param = new Dictionary <string, object>();

            sql.Parameters.ForEach(token =>
            {
                param[adapter.Settings.ParamterName(token)] = requestid;
            });

            //var applyDto = provider.QueryFirst<ApplyDto>(connection, sql.ToString(adapter.Settings), param);
        }
示例#4
0
        /// <inheritdoc />
        public override void ConfigureServices(IServiceCollection services)
        {
            DbConnectionManager.RegisterAdapter(new MySqlLtsAdapter());
            LinqConnectionManager.RegisterAdapter(new SqlServerLinqAdapter());
            DbConnectionManager.RegisterDatabaseFor <DapperFor>();

            services.AddSingleton <IDbTransactionProvider, DbTransactionProvider>()
            .AddDefaultRepositories <EfContext>();

            ModelValidator.CustomValidate <RequiredAttribute>((attr, context) =>
            {
                return($"{context.DisplayName}Ϊ±ØÌî×Ö¶Î!");
            });

            base.ConfigureServices(services);

            services
            .UseDependencyInjection()
            .UseMiddleware();
        }