Bouyei.DbFactory - .net 多种数据库统一接口


MIT
Windows
C#

软件简介

1、.net 数据库访问通信接口封装,支持 ORM 和 ado.net 方式;ado.net(包含)支持 SQL
server,DB2,Oracle,MySQL,Postgresql,access 等;

2、支持.net Core 2.0

2、支持数据库表双向同步

       static void Main(string[] args) 
        {
            ////ado.net 使用例子
            string connectionString = string.Empty;
            AdoProvider dbProvider = AdoProvider.CreateProvider(connectionString,ProviderType.SqlServer);
            var adort = dbProvider.Query(new DbExecuteParameter()
            {
                CommandText = "select * from user"
            });

            //ORM 使用例子
            IOrmProvider ormProvider = OrmProvider.CreateProvider("DbConnection");
            try
            {
                User item = ormProvider.GetById(1);
                UserDto ud = new UserDto()
                {
                    UserName = "http://aileenyin.com/"
                };

                var query = ormProvider.Query().FirstOrDefault();

                //使用mapper修改对象
                EntityMapper.MapTo(ud, item);
                ormProvider.Update(item);
                //保存修改
                int rt = ormProvider.SaveChanges();
            }
            catch(Exception ex)
            {
                Console.Write(ex.Message);
            }

            //数据库表同步
            ListtableSchema = new List();
            tableSchema.Add(new SyncTableSchema()
            {
                TableName = "user",
                Columns = new List() {
                    new SyncColumnName("name"){ DataType="nvarchar",Size=50},
                    new SyncColumnName("id"){ DataType="int", IsPrimaryKey= true, IncrementStart=1, IncrementStep=1,Size=4},
                    new  SyncColumnName("no"){ DataType="int",Size=4},
                    new SyncColumnName("age"){DataType="int",Size=4 }
                }
            });

            string sourceConnString = "Server=127.0.0.1;Database=A;User Id=sa;Password=bouyei;";
            string targetConnString = "Server=127.0.0.1;Database=B;User Id=sa;Password=bouyei;";
            dbSyncProvider = DbSyncProvider.CreateProvider(sourceConnString, targetConnString,
                "ScopeName", tableSchema);

            //清空同步记录设置 需要重新初始化设置
            dbSyncProvider.DeprovisionScope();

            //重设同步记录设置 初次使用需要初始化
            // dbSyncProvider.ProvisionScope(null);

            dbSyncProvider.ProvisionScope(new List() {
                 new SyncFilterSchema(){
                      FilterColumns=new List(){"[age]"},
                      FilterClause="[side].[age]>20"
                 }
            });

            var rt = dbSyncProvider.ExecuteSync(new SyncParameter()
            {
                Direction = SyncDirectionType.Upload,
            });

            Console.WriteLine("beginTime" + rt.SyncStartTime);
            Console.WriteLine("endTime" + rt.SyncEndTime);
            Console.WriteLine("UploadChangesApplied" + rt.UploadChangesApplied);
            Console.WriteLine("UploadChangesTotal" + rt.UploadChangesTotal);
        }
        class UserDto
        {
           public string UserName { get; set; }

            public string Pwd { get; set; }
        }