mirror of
https://github.com/anjoy8/Blog.Core.git
synced 2025-02-08 02:39:26 +08:00
Created support muti db (markdown)
parent
b1445f3f8c
commit
eacb7e13ab
81
support-muti-db.md
Normal file
81
support-muti-db.md
Normal file
|
@ -0,0 +1,81 @@
|
|||
## appsettings.json
|
||||
|
||||
### 1、开启多库操作阀门为true
|
||||
|
||||
```
|
||||
"MutiDBEnabled": true
|
||||
```
|
||||
|
||||
### 2、配置多个连接字符串
|
||||
|
||||
```
|
||||
// 如果要启用那个,就必须开启对应的阀门Enabled为true,
|
||||
// 同时必须要配置不同的连接ID —— ConnId
|
||||
// 注意♥,多个数据库必须都存在,如果不存在肯定连不上。
|
||||
|
||||
"DBS": [
|
||||
/*
|
||||
MySql = 0,
|
||||
SqlServer = 1,
|
||||
Sqlite = 2,
|
||||
Oracle = 3,
|
||||
PostgreSQL = 4
|
||||
*/
|
||||
{
|
||||
"ConnId": "WMBLOG_SQLITE",
|
||||
"DBType": 2,
|
||||
"Enabled": true,
|
||||
"Connection": "WMBlog.db" //只写数据库名就行,我会拼接字符串
|
||||
},
|
||||
{
|
||||
"ConnId": "WMBLOG_MSSQL",
|
||||
"DBType": 1,
|
||||
"Enabled": true,
|
||||
"Connection": "Server=.;Database=WMBlogDB;User ID=sa;Password=123;",
|
||||
"ProviderName": "System.Data.SqlClient"
|
||||
},
|
||||
{
|
||||
"ConnId": "WMBLOG_MYSQL",
|
||||
"DBType": 0,
|
||||
"Enabled": true,
|
||||
"Connection": "Server=localhost; Port=3306;Stmt=; Database=wmblogdb; Uid=root; Pwd=456;"
|
||||
},
|
||||
{
|
||||
"ConnId": "WMBLOG_ORACLE",
|
||||
"DBType": 3,
|
||||
"Enabled": false,
|
||||
"Connection": "Provider=OraOLEDB.Oracle; Data Source=WMBlogDB; User Id=sss; Password=789;",
|
||||
"OracleConnection_other1": "User ID=sss;Password=789;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.8.65)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME = orcl)))"
|
||||
}
|
||||
],
|
||||
|
||||
```
|
||||
|
||||
### 3、配置主数据库ID
|
||||
|
||||
```
|
||||
//在appsettings.json中配置主数据库连接ID
|
||||
|
||||
"MainDB": "WMBLOG_SQLITE",//当前项目的主库,连接字符串的Enabled必须为true
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 4、配置实体Model特性,对应的数据库连接Id
|
||||
|
||||
// 第一个参数是表名,第二个参数是对应的appsettings.json中的连接id
|
||||
// 如果这个特性不写,默认的就是主数据库
|
||||
|
||||
```
|
||||
[SugarTable("PasswordLib", "WMBLOG_MSSQL")]
|
||||
public class PasswordLib
|
||||
{
|
||||
[SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int PLID { get; set; }
|
||||
|
||||
// more...
|
||||
|
||||
}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user