Bitter.Core系列二:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore ORM 之数据库连接
如果你需要的是 .NETFRAMEWORK 版本的,请移步到:https://www.cnblogs.com/davidchild/p/14617771.html 参考配置
Bitter.Core NETCore 相当的简单易用,下面附上使用示例:
数据中连接:请在你的NETCORE 项目中 创建:Bitter.json 配置文件,然后追加如下配置内容:
-
MSSQL 连接(读写分离配置对),如果读写分离都指向同一个库的话,那么也需要这样配置,只是,配置的Value 的字符串保持一致就行。
{ "connectionString":[ { "dbType": "System.Data.SqlClient", "name": "MainData.Reader", "value": "Min Pool Size=10;Max Pool Size=500;Connection Timeout=50;Data Source=192.168.99.66,12033;Initial Catalog=readdbname;Persist Security Info=True;User ID=username;Password=pwd; pooling=false" }, { "dbType": "System.Data.SqlClient", "name": "MainData.Writer", "value": "Min Pool Size=10;Max Pool Size=500;Connection Timeout=50;Data Source=192.168.99.66,12033;Initial Catalog=writedbname;Persist Security Info=True;User ID=test;Password=pwd; pooling=false" } ] }
2.MySql 连接(读写分离配置对),如果读写分离都指向同一个库的话,那么也需要这样配置,只是,配置的 Value 的字符串保持一致就
{ "connectionString":[ { "dbType": "MySql.Data.MySqlClient", "name": "MainData.Reader", "value": "Server=.;Port=3306;Database=dbname;Uid=root;Pwd=pwd;Charset=utf8;SslMode=none;Allow User Variables=True;" }, { "dbType": "MySql.Data.MySqlClient", "name": "MainData.Writer", "value": "Server=.;Port=3306;Database=dbname;Uid=root;Pwd=pwd;Charset=utf8;SslMode=none;Allow User Variables=True;" } ] }
3.接配置(读写分离配置对)
{ "connectionString":[ { "dbType": "System.Data.SqlClient", "name": "MainData.Reader", "value": "Min Pool Size=10;Max Pool Size=500;Connection Timeout=50;Data Source=192.168.99.66,12033;Initial Catalog=readdbname_1;Persist Security Info=True;User ID=username;Password=pwd; pooling=false" }, { "dbType": "System.Data.SqlClient", "name": "MainData.Writer", "value": "Min Pool Size=10;Max Pool Size=500;Connection Timeout=50;Data Source=192.168.99.66,12033;Initial Catalog=writedbname_1;Persist Security Info=True;User ID=test;Password=pwd; pooling=false" }, { "dbType": "System.Data.SqlClient", "name": "database2.Reader", //注意,name 的值可以自定义,我这里为了方便,先取值为database2, 后面的 Reader 代表着读库 在之后的数据操作代码中在多库连接操作中会使用到。 "value": "Min Pool Size=10;Max Pool Size=500;Connection Timeout=50;Data Source=192.168.99.66,12033;Initial Catalog=readdbname_1;Persist Security Info=True;User ID=username;Password=pwd; pooling=false" }, { "dbType": "System.Data.SqlClient", "name": "database2.Writer", //注意,name 的值可以自定义,我这里为了方便,先取值为database2, 后面的 Writer 代表着写库 在之后的数据操作代码中在多库连接操作中会使用到。 "value": "Min Pool Size=10;Max Pool Size=500;Connection Timeout=50;Data Source=192.168.99.66,12033;Initial Catalog=writedbname_1;Persist Security Info=True;User ID=test;Password=pwd; pooling=false" } ] }