You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
26 KiB
JavaScript
1 line
26 KiB
JavaScript
"use strict";(self.webpackChunkfurion=self.webpackChunkfurion||[]).push([[9706],{5423:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>s,metadata:()=>l,toc:()=>d});var o=n(5893),t=n(1151);n(4996),n(4866),n(5162);const s={id:"dbcontext-multi-database",title:"9.19 \u591a\u79cd\u6570\u636e\u5e93\u64cd\u4f5c",sidebar_label:"9.19 \u591a\u79cd\u6570\u636e\u5e93\u64cd\u4f5c \u2728"},i=void 0,l={id:"dbcontext-multi-database",title:"9.19 \u591a\u79cd\u6570\u636e\u5e93\u64cd\u4f5c",description:"\u5982\u679c\u8fde\u63a5\u5b57\u7b26\u4e32\u662f\u914d\u7f6e\u5728\u81ea\u5b9a\u4e49\u7684 .json \u6587\u4ef6\u4e2d\uff0c\u90a3\u4e48\u5fc5\u987b\u5728 Visual Studio \u4e2d\u914d\u7f6e .json \u53f3\u952e\u5c5e\u6027\uff0c\u8bbe\u7f6e \u590d\u5236 \u8f93\u51fa\u76ee\u5f55\u4e3a \u5982\u679c\u8f83\u65b0\u5219\u590d\u5236\uff0c\u751f\u6210\u64cd\u4f5c\u4e3a \u5185\u5bb9\u3002",source:"@site/docs/dbcontext-multi-database.mdx",sourceDirName:".",slug:"/dbcontext-multi-database",permalink:"/docs/dbcontext-multi-database",draft:!1,unlisted:!1,editUrl:"https://gitee.com/dotnetchina/Furion/tree/v4/handbook/docs/dbcontext-multi-database.mdx",tags:[],version:"current",lastUpdatedBy:"MonkSoul",lastUpdatedAt:1682389320,formattedLastUpdatedAt:"Apr 25, 2023",frontMatter:{id:"dbcontext-multi-database",title:"9.19 \u591a\u79cd\u6570\u636e\u5e93\u64cd\u4f5c",sidebar_label:"9.19 \u591a\u79cd\u6570\u636e\u5e93\u64cd\u4f5c \u2728"},sidebar:"docs",previous:{title:"9.18 Sql \u9ad8\u7ea7\u4ee3\u7406",permalink:"/docs/dbcontext-sql-proxy"},next:{title:"9.20 \u6570\u636e\u5e93\u751f\u6210\u6a21\u578b (Db First)",permalink:"/docs/dbcontext-db-first"}},c={},d=[{value:"9.19.1 <code>Furion</code> \u652f\u6301\u6570\u636e\u5e93\u63d0\u4f9b\u5668",id:"9191-furion-\u652f\u6301\u6570\u636e\u5e93\u63d0\u4f9b\u5668",level:2},{value:"9.19.1.1 \u6570\u636e\u5e93\u63d0\u4f9b\u5668\u5bf9\u5e94\u5305",id:"91911-\u6570\u636e\u5e93\u63d0\u4f9b\u5668\u5bf9\u5e94\u5305",level:3},{value:"9.19.2 \u591a\u6570\u636e\u5e93\u670d\u52a1\u6ce8\u518c",id:"9192-\u591a\u6570\u636e\u5e93\u670d\u52a1\u6ce8\u518c",level:2},{value:"9.19.3 \u5404\u7c7b\u6570\u636e\u5e93\u8fde\u63a5\u5b57\u7b26\u4e32\u914d\u7f6e\u793a\u4f8b",id:"9193-\u5404\u7c7b\u6570\u636e\u5e93\u8fde\u63a5\u5b57\u7b26\u4e32\u914d\u7f6e\u793a\u4f8b",level:2},{value:"9.19.4 \u591a\u6570\u636e\u5e93\u4f7f\u7528\u65b9\u5f0f",id:"9194-\u591a\u6570\u636e\u5e93\u4f7f\u7528\u65b9\u5f0f",level:2},{value:"9.19.4.1 \u5b9e\u4f53\u4ed3\u50a8\u65b9\u5f0f",id:"91941-\u5b9e\u4f53\u4ed3\u50a8\u65b9\u5f0f",level:3},{value:"9.19.4.2 \u975e\u6cdb\u578b\u4ed3\u50a8\u65b9\u5f0f",id:"91942-\u975e\u6cdb\u578b\u4ed3\u50a8\u65b9\u5f0f",level:3},{value:"9.19.4.3 <code>Sql</code> \u4ed3\u50a8\u65b9\u5f0f",id:"91943-sql-\u4ed3\u50a8\u65b9\u5f0f",level:3},{value:"9.19.4.4 \u5b9e\u4f53\u5b9a\u4e49\u65b9\u5f0f",id:"91944-\u5b9e\u4f53\u5b9a\u4e49\u65b9\u5f0f",level:3},{value:"9.19.4.5 Linq \u51fd\u6570\u65b9\u5f0f",id:"91945-linq-\u51fd\u6570\u65b9\u5f0f",level:3},{value:"9.19.5 <code>SqlServer</code> \u4f4e\u7248\u672c\u652f\u6301\u52a8\u6001\u914d\u7f6e",id:"9195-sqlserver-\u4f4e\u7248\u672c\u652f\u6301\u52a8\u6001\u914d\u7f6e",level:2},{value:"9.19.6 <code>MySql</code> \u65f6\u533a\u95ee\u9898/\u5c11 8 \u5c0f\u65f6\u95ee\u9898",id:"9196-mysql-\u65f6\u533a\u95ee\u9898\u5c11-8-\u5c0f\u65f6\u95ee\u9898",level:2},{value:"9.19.7 <code>snake_case</code> \u98ce\u683c\u8868\u540d\u548c\u5b57\u6bb5",id:"9197-snake_case-\u98ce\u683c\u8868\u540d\u548c\u5b57\u6bb5",level:2},{value:"9.19.8 \u53cd\u9988\u4e0e\u5efa\u8bae",id:"9198-\u53cd\u9988\u4e0e\u5efa\u8bae",level:2}];function a(e){const r={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,t.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(r.admonition,{title:"\u8fde\u63a5\u5b57\u7b26\u4e32\u914d\u7f6e\u6ce8\u610f\u4e8b\u9879",type:"warning",children:[(0,o.jsxs)(r.p,{children:["\u5982\u679c\u8fde\u63a5\u5b57\u7b26\u4e32\u662f\u914d\u7f6e\u5728\u81ea\u5b9a\u4e49\u7684 ",(0,o.jsx)(r.code,{children:".json"})," \u6587\u4ef6\u4e2d\uff0c\u90a3\u4e48\u5fc5\u987b\u5728 ",(0,o.jsx)(r.code,{children:"Visual Studio"})," \u4e2d\u914d\u7f6e ",(0,o.jsx)(r.code,{children:".json"})," \u53f3\u952e\u5c5e\u6027\uff0c\u8bbe\u7f6e ",(0,o.jsx)(r.code,{children:"\u590d\u5236"})," \u8f93\u51fa\u76ee\u5f55\u4e3a ",(0,o.jsx)(r.code,{children:"\u5982\u679c\u8f83\u65b0\u5219\u590d\u5236"}),"\uff0c\u751f\u6210\u64cd\u4f5c\u4e3a ",(0,o.jsx)(r.code,{children:"\u5185\u5bb9"}),"\u3002"]}),(0,o.jsx)(r.p,{children:"\u5426\u5219\u5c31\u4f1a\u63d0\u793a\u627e\u4e0d\u5230\u914d\u7f6e\u6216\u8fde\u63a5\u5b57\u7b26\u4e32\u7684\u9519\u8bef\u3002"})]}),"\n",(0,o.jsxs)(r.h2,{id:"9191-furion-\u652f\u6301\u6570\u636e\u5e93\u63d0\u4f9b\u5668",children:["9.19.1 ",(0,o.jsx)(r.code,{children:"Furion"})," \u652f\u6301\u6570\u636e\u5e93\u63d0\u4f9b\u5668"]}),"\n",(0,o.jsxs)(r.table,{children:[(0,o.jsx)(r.thead,{children:(0,o.jsxs)(r.tr,{children:[(0,o.jsx)(r.th,{children:"SqlServer"}),(0,o.jsx)(r.th,{children:"Sqlite"}),(0,o.jsx)(r.th,{children:"Cosmos"}),(0,o.jsx)(r.th,{children:"InMemoryDatabase"}),(0,o.jsx)(r.th,{children:"MySql"}),(0,o.jsx)(r.th,{children:"PostgreSQL"}),(0,o.jsx)(r.th,{children:"Oracle"}),(0,o.jsx)(r.th,{children:"Firebird"}),(0,o.jsx)(r.th,{children:"Dm"})]})}),(0,o.jsx)(r.tbody,{children:(0,o.jsxs)(r.tr,{children:[(0,o.jsx)(r.td,{children:"\u2714"}),(0,o.jsx)(r.td,{children:"\u2714"}),(0,o.jsx)(r.td,{children:"\u2714"}),(0,o.jsx)(r.td,{children:"\u2714"}),(0,o.jsx)(r.td,{children:"\u2714"}),(0,o.jsx)(r.td,{children:"\u2714"}),(0,o.jsx)(r.td,{children:"\u2714"}),(0,o.jsx)(r.td,{children:"\u2714"}),(0,o.jsx)(r.td,{children:"\u2714"})]})})]}),"\n",(0,o.jsx)(r.h3,{id:"91911-\u6570\u636e\u5e93\u63d0\u4f9b\u5668\u5bf9\u5e94\u5305",children:"9.19.1.1 \u6570\u636e\u5e93\u63d0\u4f9b\u5668\u5bf9\u5e94\u5305"}),"\n",(0,o.jsxs)(r.ul,{children:["\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"SqlServer"}),"\uff1a",(0,o.jsx)(r.code,{children:"Microsoft.EntityFrameworkCore.SqlServer"})," (\u652f\u6301 SqlServer 2005 +)"]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"Sqlite"}),"\uff1a",(0,o.jsx)(r.code,{children:"Microsoft.EntityFrameworkCore.Sqlite"})]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"Cosmos"}),"\uff1a",(0,o.jsx)(r.code,{children:"Microsoft.EntityFrameworkCore.Cosmos"})]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"InMemoryDatabase"}),"\uff1a",(0,o.jsx)(r.code,{children:"Microsoft.EntityFrameworkCore.InMemory"})]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"MySql"}),"\n",(0,o.jsxs)(r.ul,{children:["\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"Pomelo.EntityFrameworkCore.MySql"}),"\uff1a(\u652f\u6301 MySql 5.x +)"]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"MySql.EntityFrameworkCore"}),"\uff1a\u652f\u6301 (MySql 8.x +)"]}),"\n"]}),"\n"]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"PostgreSQL"}),"\uff1a",(0,o.jsx)(r.code,{children:"Npgsql.EntityFrameworkCore.PostgreSQL"})]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"Oracle"}),"\uff1a",(0,o.jsx)(r.code,{children:"Oracle.EntityFrameworkCore"})," \uff08\u652f\u6301 Oracle 10 +\uff09"]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"Firebird"}),"\uff1a",(0,o.jsx)(r.code,{children:"FirebirdSql.EntityFrameworkCore.Firebird"})]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"Dm"}),"\uff1a",(0,o.jsx)(r.code,{children:"Microsoft.EntityFrameworkCore.Dm"})]}),"\n"]}),"\n",(0,o.jsx)(r.admonition,{title:"\u5c0f\u77e5\u8bc6",type:"tip",children:(0,o.jsxs)(r.p,{children:["\u8fd9\u4e9b\u6570\u636e\u5e93\u5305\u5e94\u8be5\u5b89\u88c5\u5728 ",(0,o.jsx)(r.code,{children:"Furion.EntityFramework.Core"})," \u5c42\u3002\u7279\u6b8a\u60c5\u51b5\u9700\u5b89\u88c5\u5728 ",(0,o.jsx)(r.code,{children:"Furion.Core"})," \u5c42\u4e2d\uff0c\u5982 ",(0,o.jsx)(r.code,{children:"Mysql"})," ",(0,o.jsx)(r.code,{children:"HasCharset()"})," \u914d\u7f6e\u3002"]})}),"\n",(0,o.jsx)(r.h2,{id:"9192-\u591a\u6570\u636e\u5e93\u670d\u52a1\u6ce8\u518c",children:"9.19.2 \u591a\u6570\u636e\u5e93\u670d\u52a1\u6ce8\u518c"}),"\n",(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:'// \u6ce8\u518c SqlServer\r\noptions.AddDbPool<FurionDbContext>(DbProvider.SqlServer);\r\noptions.AddDbPool<FurionDbContext>($"{DbProvider.SqlServer}@2005"); // \u652f\u6301 2005 \u6570\u636e\u5e93\r\noptions.AddDbPool<FurionDbContext>($"{DbProvider.SqlServer}@2008"); // \u652f\u6301 2008 \u6570\u636e\u5e93\r\n\r\n// \u6ce8\u518c Sqlite\r\noptions.AddDbPool<FurionDbContext>(DbProvider.Sqlite);\r\n\r\n// \u6ce8\u518c Cosmos\r\noptions.AddDbPool<FurionDbContext>(DbProvider.Cosmos);\r\n\r\n// \u6ce8\u518c InMemoryDatabase\r\noptions.AddDbPool<FurionDbContext>(DbProvider.InMemoryDatabase);\r\n\r\n// \u6ce8\u518c MySql\r\noptions.AddDbPool<FurionDbContext>(DbProvider.MySql);\r\noptions.AddDbPool<FurionDbContext>($"{DbProvider.MySql}@8.0.22"); // \u53ef\u4ee5\u6307\u5b9a\u7248\u672c\u53f7\r\noptions.AddDbPool<FurionDbContext>(DbProvider.MySqlOfficial); // \u4f7f\u7528 MySql \u5b98\u65b9\u5305\uff08MySql.EntityFrameworkCore\uff09\r\n\r\n// \u6ce8\u518c PostgreSQL\r\noptions.AddDbPool<FurionDbContext>(DbProvider.Npgsql);\r\n\r\n// \u6ce8\u518c Oracle\r\noptions.AddDbPool<FurionDbContext>(DbProvider.Oracle);\r\noptions.AddDbPool<FurionDbContext>($"{DbProvider.Oracle}@11"); // \u652f\u6301 Oracle 11 \u7248\u672c\r\n\r\n// \u6ce8\u518c Firebird\r\noptions.AddDbPool<FurionDbContext>(DbProvider.Firebird);\r\n\r\n// \u6ce8\u518c Dm\r\noptions.AddDbPool<FurionDbContext>(DbProvider.Dm);\n'})}),"\n",(0,o.jsxs)(r.admonition,{title:"\u65b0\u7248 SqlServer/MySQL/Oracle \u6ce8\u610f",type:"caution",children:[(0,o.jsxs)(r.p,{children:[(0,o.jsx)(r.code,{children:"SqlServer"})," \u517c\u5bb9 ",(0,o.jsx)(r.code,{children:"2005-2008"})," \u5199\u6cd5\uff1a"]}),(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:'services.AddDatabaseAccessor(options =>\r\n{\r\n options.AddDbPool<FurionDbContext>($"{DbProvider.SqlServer}@2005"); // \u652f\u6301 2005 \u6570\u636e\u5e93\r\n options.AddDbPool<FurionDbContext>($"{DbProvider.SqlServer}@2008"); // \u652f\u6301 2008 \u6570\u636e\u5e93\r\n});\n'})}),(0,o.jsxs)(r.p,{children:[(0,o.jsx)(r.code,{children:"MySQL"})," \u517c\u5bb9\u65e7\u7248\u672c\uff08\u5e26\u7248\u672c\u53f7\uff09\u5199\u6cd5\uff1a"]}),(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:'services.AddDatabaseAccessor(options =>\r\n{\r\n options.AddDbPool<FurionDbContext>($"{DbProvider.MySql}@8.0.22");\r\n});\n'})}),(0,o.jsxs)(r.p,{children:["\u5982\u679c\u4f7f\u7528\u4e86 ",(0,o.jsx)(r.code,{children:"MySql.EntityFrameworkCore"})," \u5305\uff0c\u5219\u9700\u6539\u4e3a\u4ee5\u4e0b\u6ce8\u518c\uff1a"]}),(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"services.AddDatabaseAccessor(options =>\r\n{\r\n options.AddDbPool<FurionDbContext>(DbProvider.MySqlOfficial);\r\n});\n"})}),(0,o.jsxs)(r.p,{children:[(0,o.jsx)(r.code,{children:"Oracle"})," \u517c\u5bb9 ",(0,o.jsx)(r.code,{children:"11"})," \u7248\u672c"]}),(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {3-4,6-10}",children:'services.AddDatabaseAccessor(options =>\r\n{\r\n // \u6b63\u5e38\u8fd9\u6837\u914d\u7f6e\u5373\u53ef\r\n options.AddDbPool<FurionDbContext>($"{DbProvider.Oracle}@11");\r\n\r\n // \u5982\u679c\u4f9d\u7136\u51fa\u73b0 ORA-00933: SQL \u9519\u8bef\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u914d\u7f6e\uff1a\r\n options.AddDbPool<FurionDbContext>($"{DbProvider.Oracle}@11", optionBuilder: (ses, opt) =>\r\n {\r\n opt.UseOracle(b => b.UseOracleSQLCompatibility("11"));\r\n });\r\n});\n'})})]}),"\n",(0,o.jsx)(r.h2,{id:"9193-\u5404\u7c7b\u6570\u636e\u5e93\u8fde\u63a5\u5b57\u7b26\u4e32\u914d\u7f6e\u793a\u4f8b",children:"9.19.3 \u5404\u7c7b\u6570\u636e\u5e93\u8fde\u63a5\u5b57\u7b26\u4e32\u914d\u7f6e\u793a\u4f8b"}),"\n",(0,o.jsxs)(r.ul,{children:["\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"Sqlite"}),"\uff1a",(0,o.jsx)(r.code,{children:"Data Source=./Furion.db"})]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"MySql"}),"\uff1a",(0,o.jsx)(r.code,{children:"Data Source=localhost;Database=Furion;User ID=root;Password=000000;pooling=true;port=3306;sslmode=none;CharSet=utf8;"})]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"SqlServer"}),"\uff1a",(0,o.jsx)(r.code,{children:"Server=localhost;Database=Furion;User=sa;Password=000000;MultipleActiveResultSets=True;Encrypt=True;TrustServerCertificate=True;"})]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"Oracle"}),"\uff1a",(0,o.jsx)(r.code,{children:"User Id=orcl;Password=orcl;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)))"})]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"PostgreSQL"}),"\uff1a",(0,o.jsx)(r.code,{children:"PORT=5432;DATABASE=postgres;HOST=127.0.0.1;PASSWORD=postgres;USER ID=postgres;"})]}),"\n"]}),"\n",(0,o.jsx)(r.h2,{id:"9194-\u591a\u6570\u636e\u5e93\u4f7f\u7528\u65b9\u5f0f",children:"9.19.4 \u591a\u6570\u636e\u5e93\u4f7f\u7528\u65b9\u5f0f"}),"\n",(0,o.jsxs)(r.p,{children:[(0,o.jsx)(r.code,{children:"Furion"})," \u901a\u8fc7\u72ec\u521b\u7684 ",(0,o.jsx)(r.code,{children:"\u6570\u636e\u5e93\u4e0a\u4e0b\u6587\u5b9a\u4f4d\u5668"})," \u5b9e\u73b0\u591a\u6570\u636e\u5e93\u7075\u6d3b\u64cd\u4f5c\u5207\u6362\u3002\u53ea\u9700\u8981\u4e3a\u6bcf\u4e00\u79cd\u6570\u636e\u5e93\u7ed1\u5b9a\u552f\u4e00\u7684\u6570\u636e\u5e93\u4e0a\u4e0b\u6587\u5b9a\u4f4d\u5668\u5373\u53ef\u3002"]}),"\n",(0,o.jsxs)(r.p,{children:["\u4ee5\u4e0b\u662f ",(0,o.jsx)(r.code,{children:"Furion"})," \u652f\u6301\u591a\u6570\u636e\u5e93\u64cd\u4f5c\u7684\u5b9e\u4f8b\uff1a"]}),"\n",(0,o.jsx)(r.h3,{id:"91941-\u5b9e\u4f53\u4ed3\u50a8\u65b9\u5f0f",children:"9.19.4.1 \u5b9e\u4f53\u4ed3\u50a8\u65b9\u5f0f"}),"\n",(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"// \u5207\u6362\u5230 MSSQL \u64cd\u4f5c Person\u8868\r\nvar mssqlRepository = personRepository.Change<Person, MsSqlDbContextLocator>();\r\n\r\n// \u5207\u6362\u5230 MySql \u64cd\u4f5c Person\u8868\r\nvar mysqlRepository = personRepository.Change<Person, MySqlDbContextLocator>();\r\n\r\n// \u5207\u6362\u5230 Sqlite \u64cd\u4f5c Person\u8868\r\nvar sqliteRepository = personRepository.Change<Person, SqliteDbContextLocator>();\r\n\n"})}),"\n",(0,o.jsx)(r.h3,{id:"91942-\u975e\u6cdb\u578b\u4ed3\u50a8\u65b9\u5f0f",children:"9.19.4.2 \u975e\u6cdb\u578b\u4ed3\u50a8\u65b9\u5f0f"}),"\n",(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"// \u5207\u6362\u5230 MSSQL \u64cd\u4f5c Person\u8868\r\nvar mssqlRepository = repository.Change<Person, MsSqlDbContextLocator>();\r\n\r\n// \u5207\u6362\u5230 MySql \u64cd\u4f5c Person\u8868\r\nvar mysqlRepository = repository.Change<Person, MySqlDbContextLocator>();\r\n\r\n// \u5207\u6362\u5230 Sqlite \u64cd\u4f5c Person\u8868\r\nvar sqliteRepository = repository.Change<Person, SqliteDbContextLocator>();\n"})}),"\n",(0,o.jsxs)(r.h3,{id:"91943-sql-\u4ed3\u50a8\u65b9\u5f0f",children:["9.19.4.3 ",(0,o.jsx)(r.code,{children:"Sql"})," \u4ed3\u50a8\u65b9\u5f0f"]}),"\n",(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"// \u5207\u6362\u5230 MSSQL \u64cd\u4f5c Person\u8868\r\nvar mssqlRepository = sqlRepository.Change<MsSqlDbContextLocator>();\r\n\r\n// \u5207\u6362\u5230 MySql \u64cd\u4f5c Person\u8868\r\nvar mysqlRepository = sqlRepository.Change<MySqlDbContextLocator>();\r\n\r\n// \u5207\u6362\u5230 Sqlite \u64cd\u4f5c Person\u8868\r\nvar sqliteRepository = sqlRepository.Change<SqliteDbContextLocator>();\n"})}),"\n",(0,o.jsx)(r.h3,{id:"91944-\u5b9e\u4f53\u5b9a\u4e49\u65b9\u5f0f",children:"9.19.4.4 \u5b9e\u4f53\u5b9a\u4e49\u65b9\u5f0f"}),"\n",(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"\r\n// \u652f\u6301\u4e00\u4e2a\u6570\u636e\u5e93\r\npublic class Person: IEntity<MySqlDbContextLocator>\r\n{\r\n // ....\r\n}\r\n\r\n// \u652f\u6301\u591a\u4e2a\u6570\u636e\u5e93\r\npublic class Person: IEntity<MySqlDbContextLocator, SqliteDbContextLocator>\r\n{\r\n // ....\r\n}\n"})}),"\n",(0,o.jsx)(r.admonition,{title:"\u5c0f\u77e5\u8bc6",type:"tip",children:(0,o.jsxs)(r.p,{children:["\u6240\u6709\u7684 ",(0,o.jsx)(r.code,{children:"\u5b9e\u4f53\u4f9d\u8d56\u63a5\u53e3\u6216\u62bd\u8c61\u7c7b"})," \u90fd\u652f\u6301\u6cdb\u578b\u65b9\u5f0f \u6307\u5b9a \u6570\u636e\u5e93\u4e0a\u4e0b\u6587\u5b9a\u4f4d\u5668\uff0c\u6700\u591a\u652f\u6301 ",(0,o.jsx)(r.code,{children:"8"})," \u4e2a\u3002"]})}),"\n",(0,o.jsx)(r.h3,{id:"91945-linq-\u51fd\u6570\u65b9\u5f0f",children:"9.19.4.5 Linq \u51fd\u6570\u65b9\u5f0f"}),"\n",(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:'public static class QueryFunctions\r\n{\r\n [QueryableFunction("FN_GetId", "dbo", typeof(MySqlDbContextLocator), typeof(SqliteDbContextLocator))]\r\n public static int GetId(int id) => throw new NotSupportedException();\r\n}\n'})}),"\n",(0,o.jsxs)(r.h2,{id:"9195-sqlserver-\u4f4e\u7248\u672c\u652f\u6301\u52a8\u6001\u914d\u7f6e",children:["9.19.5 ",(0,o.jsx)(r.code,{children:"SqlServer"})," \u4f4e\u7248\u672c\u652f\u6301\u52a8\u6001\u914d\u7f6e"]}),"\n",(0,o.jsxs)(r.p,{children:["\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0c\u53ea\u9700\u8981\u5728\u6ce8\u518c\u7684\u65f6\u5019\u6307\u5b9a ",(0,o.jsx)(r.code,{children:"@2008"})," \u6570\u636e\u5e93\u5373\u53ef\uff0c\u6709\u4e9b\u65f6\u5019\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5728 ",(0,o.jsx)(r.code,{children:"DbContext"})," \u7684 ",(0,o.jsx)(r.code,{children:"OnConfigure"})," \u4e2d\u914d\u7f6e\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u9700\u8981\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a"]}),"\n",(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {4}",children:"protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)\r\n{\r\n optionsBuilder.UseSqlServer(DbProvider.GetConnectionString<TDbContext>())\r\n .ReplaceService<IQueryTranslationPostprocessorFactory, SqlServer2008QueryTranslationPostprocessorFactory>();\r\n base.OnConfiguring(optionsBuilder);\r\n}\n"})}),"\n",(0,o.jsx)(r.admonition,{title:"\u5c0f\u77e5\u8bc6",type:"note",children:(0,o.jsxs)(r.p,{children:[(0,o.jsx)(r.code,{children:"DbProvider.GetConnectionString<TDbContext>()"})," \u662f\u83b7\u53d6\u5bf9\u5e94\u4e0a\u4e0b\u6587\u914d\u7f6e\u7684\u6570\u636e\u5e93\u94fe\u63a5\u5b57\u7b26\u4e32\u3002"]})}),"\n",(0,o.jsxs)(r.h2,{id:"9196-mysql-\u65f6\u533a\u95ee\u9898\u5c11-8-\u5c0f\u65f6\u95ee\u9898",children:["9.19.6 ",(0,o.jsx)(r.code,{children:"MySql"})," \u65f6\u533a\u95ee\u9898/\u5c11 8 \u5c0f\u65f6\u95ee\u9898"]}),"\n",(0,o.jsxs)(r.p,{children:["\u53ef\u67e5\u9605\u76f8\u5173 ",(0,o.jsx)(r.code,{children:"Issue"}),"\uff1a",(0,o.jsx)(r.a,{href:"https://gitee.com/dotnetchina/Furion/issues/I3RSCO",children:"https://gitee.com/dotnetchina/Furion/issues/I3RSCO"})]}),"\n",(0,o.jsxs)(r.h2,{id:"9197-snake_case-\u98ce\u683c\u8868\u540d\u548c\u5b57\u6bb5",children:["9.19.7 ",(0,o.jsx)(r.code,{children:"snake_case"})," \u98ce\u683c\u8868\u540d\u548c\u5b57\u6bb5"]}),"\n",(0,o.jsxs)(r.p,{children:["\u9ed8\u8ba4\u60c5\u51b5\u4e0b ",(0,o.jsx)(r.code,{children:"EFCore"})," \u5c06\u4f7f\u7528\u548c\u6a21\u578b\u5b9a\u4e49\u4e00\u81f4\u7684\u65b9\u5f0f\u5b9a\u4e49\u8868\u548c\u5b57\u6bb5\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7 ",(0,o.jsx)(r.a,{href:"https://github.com/efcore/EFCore.NamingConventions",children:"https://github.com/efcore/EFCore.NamingConventions"})," \u62d3\u5c55\u63d2\u4ef6\u6539\u53d8\u6b64\u884c\u4e3a\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a"]}),"\n",(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {2}",children:" builder.UseNpgsql()\r\n .UseLowerCaseNamingConvention();\n"})}),"\n",(0,o.jsxs)(r.p,{children:["\u5176\u4ed6\u8d44\u6599\uff1a",(0,o.jsx)(r.a,{href:"https://www.npgsql.org/efcore/modeling/table-column-naming.html",children:"https://www.npgsql.org/efcore/modeling/table-column-naming.html"})]}),"\n",(0,o.jsx)(r.h2,{id:"9198-\u53cd\u9988\u4e0e\u5efa\u8bae",children:"9.19.8 \u53cd\u9988\u4e0e\u5efa\u8bae"}),"\n",(0,o.jsx)(r.admonition,{title:"\u4e0e\u6211\u4eec\u4ea4\u6d41",type:"note",children:(0,o.jsxs)(r.p,{children:["\u7ed9 Furion \u63d0 ",(0,o.jsx)(r.a,{href:"https://gitee.com/dotnetchina/Furion/issues/new?issue",children:"Issue"}),"\u3002"]})})]})}function u(e={}){const{wrapper:r}={...(0,t.a)(),...e.components};return r?(0,o.jsx)(r,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},5162:(e,r,n)=>{n.d(r,{Z:()=>i});n(7294);var o=n(4334);const t={tabItem:"tabItem_Ymn6"};var s=n(5893);function i(e){let{children:r,hidden:n,className:i}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,o.Z)(t.tabItem,i),hidden:n,children:r})}},4866:(e,r,n)=>{n.d(r,{Z:()=>g});var o=n(7294),t=n(4334),s=n(2466),i=n(6550),l=n(469),c=n(1980),d=n(7392),a=n(12);function u(e){return o.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,o.isValidElement)(e)&&function(e){const{props:r}=e;return!!r&&"object"==typeof r&&"value"in r}(e))return e;throw new Error(`Docusaurus error: Bad <Tabs> child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:r,children:n}=e;return(0,o.useMemo)((()=>{const e=r??function(e){return u(e).map((e=>{let{props:{value:r,label:n,attributes:o,default:t}}=e;return{value:r,label:n,attributes:o,default:t}}))}(n);return function(e){const r=(0,d.l)(e,((e,r)=>e.value===r.value));if(r.length>0)throw new Error(`Docusaurus error: Duplicate values "${r.map((e=>e.value)).join(", ")}" found in <Tabs>. Every value needs to be unique.`)}(e),e}),[r,n])}function x(e){let{value:r,tabValues:n}=e;return n.some((e=>e.value===r))}function b(e){let{queryString:r=!1,groupId:n}=e;const t=(0,i.k6)(),s=function(e){let{queryString:r=!1,groupId:n}=e;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!n)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:r,groupId:n});return[(0,c._X)(s),(0,o.useCallback)((e=>{if(!s)return;const r=new URLSearchParams(t.location.search);r.set(s,e),t.replace({...t.location,search:r.toString()})}),[s,t])]}function p(e){const{defaultValue:r,queryString:n=!1,groupId:t}=e,s=h(e),[i,c]=(0,o.useState)((()=>function(e){let{defaultValue:r,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(r){if(!x({value:r,tabValues:n}))throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${r}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return r}const o=n.find((e=>e.default))??n[0];if(!o)throw new Error("Unexpected error: 0 tabValues");return o.value}({defaultValue:r,tabValues:s}))),[d,u]=b({queryString:n,groupId:t}),[p,j]=function(e){let{groupId:r}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(r),[t,s]=(0,a.Nk)(n);return[t,(0,o.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:t}),m=(()=>{const e=d??p;return x({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{m&&c(m)}),[m]);return{selectedValue:i,selectValue:(0,o.useCallback)((e=>{if(!x({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);c(e),u(e),j(e)}),[u,j,s]),tabValues:s}}var j=n(2389);const m={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(5893);function S(e){let{className:r,block:n,selectedValue:o,selectValue:i,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),a=e=>{const r=e.currentTarget,n=c.indexOf(r),t=l[n].value;t!==o&&(d(r),i(t))},u=e=>{let r=null;switch(e.key){case"Enter":a(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;r=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;r=c[n]??c[c.length-1];break}}r?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,t.Z)("tabs",{"tabs--block":n},r),children:l.map((e=>{let{value:r,label:n,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:o===r?0:-1,"aria-selected":o===r,ref:e=>c.push(e),onKeyDown:u,onClick:a,...s,className:(0,t.Z)("tabs__item",m.tabItem,s?.className,{"tabs__item--active":o===r}),children:n??r},r)}))})}function y(e){let{lazy:r,children:n,selectedValue:t}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(r){const e=s.find((e=>e.props.value===t));return e?(0,o.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map(((e,r)=>(0,o.cloneElement)(e,{key:r,hidden:e.props.value!==t})))})}function D(e){const r=p(e);return(0,v.jsxs)("div",{className:(0,t.Z)("tabs-container",m.tabList),children:[(0,v.jsx)(S,{...e,...r}),(0,v.jsx)(y,{...e,...r})]})}function g(e){const r=(0,j.Z)();return(0,v.jsx)(D,{...e,children:u(e.children)},String(r))}},1151:(e,r,n)=>{n.d(r,{Z:()=>l,a:()=>i});var o=n(7294);const t={},s=o.createContext(t);function i(e){const r=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function l(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:i(e.components),o.createElement(s.Provider,{value:r},e.children)}}}]); |