Odbc中一个通用数据库访问框架,只要支持ODBC连接的都能用ODBC去操作数据库
//Nuget 安装 SqlSugar.OdbcCore SqlSugarCore
//Nuget 安装 SqlSugar.Odbc SqlSugar
需要安装你要连接的Odbc驱动
我们可以到 控制面板\所有控制面板项\管理工具\Odbc64数据源 查看是否已安装
具体操作可以百度或者看驱动厂商的文档
格式不确性太多, 最好找厂商 或者百度
Driver={驱动名};....
//这行代码扔程序启动时 InstanceFactory.CustomAssemblies = new System.Reflection.Assembly[] { typeof(OdbcProvider).Assembly }; //按文档入门使用 SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.Odbc, ConnectionString = Config.ConnectionString, IsAutoCloseConnection = true, AopEvents = new AopEvents { OnLogExecuting = (sql, p) => { Console.WriteLine(sql); } } });
1、不支持CodeFirst
2、兼容性未知 DbFirst
3、兼容性未知 普通用的CRUD
4、原生脚本兼容完美
//sql var dt=db.Ado.GetDataTable("select*from order where @id>0 or name=@name", new List<SugarParameter>(){ new SugarParameter("@id",1), new SugarParameter("@name","2") }); //sql var dt2 = db.Ado.GetDataTable("select * from order where @id>0 or name=@name", new { id = 1, name = "2" }); //Stored Procedure //var dt3 = db.Ado.UseStoredProcedure().GetDataTable("sp_school", new { name = "张三", age = 0 }); //var nameP = new SugarParameter("@name", "张三"); //var ageP = new SugarParameter("@age", null, true);//isOutput=true //var dt4 = db.Ado.UseStoredProcedure().GetDataTable("sp_school", nameP, ageP); //There are many methods to under db.ado var list= db.Ado.SqlQuery<Order>("select * from order "); var intValue=db.Ado.SqlQuerySingle<int>("select 1 from dual"); db.Ado.ExecuteCommand("delete from order where id>1000"); db.Ado.ExecuteCommand($"delete from order where id>1000");
更多ADO用法:
https://www.donet5.com/Home/Doc?typeId=1198
默认情况下odbc是没有转译符号的,不同库不一样比如像sqlserver是[] oracle是"" mysql是``
//点不出来就更新DLL OdbcConfig.SqlTranslationLeft = "\""; OdbcConfig.SqlTranslationRight = "\"";
默认就好什么不用配置
//升级到 SqlSugar.OdbcCore 5.1.4.160+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.Odbc,//odbc方式连接 ConnectionString = Config.ConnectionString, IsAutoCloseConnection = true, MoreSettings=new ConnMoreSettings() { DatabaseModel=DbType.SqlServer//强制SQLSERVER分页 } });
启用老版本兼容+DatabaseModel等于SqlServer 会使用rownumber分页
rownumber分页很多数据库都能用
//程序启动时加上这句话 OdbcConfig.IsCompatibleWithOldDatabaseVersion = true; SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.Odbc,//odbc方式连接 ConnectionString = Config.ConnectionString, IsAutoCloseConnection = true, MoreSettings=new ConnMoreSettings() { DatabaseModel=DbType.SqlServer//强制SQLSERVER分页 } });
先看文档安装,如果发布后还报错按下面操作
//程序启动时加 InstanceFactory.CustomAssemblies =new System.Reflection.Assembly[] { typeof(OdbcProvider).Assembly };
2016 © donet5.comApache Licence 2.0