"use strict";(self.webpackChunkfurion=self.webpackChunkfurion||[]).push([[5128],{5718:(n,e,t)=>{t.r(e),t.d(e,{assets:()=>d,contentTitle:()=>o,default:()=>h,frontMatter:()=>a,metadata:()=>c,toc:()=>l});var r=t(5893),i=t(1151),s=t(4996);const a={id:"saas",title:"11. SaaS \u591a\u79df\u6237",sidebar_label:"11. SaaS \u591a\u79df\u6237"},o=void 0,c={id:"saas",title:"11. SaaS \u591a\u79df\u6237",description:"11.1 \u4ec0\u4e48\u662f SaaS",source:"@site/docs/saas.mdx",sourceDirName:".",slug:"/saas",permalink:"/docs/saas",draft:!1,unlisted:!1,editUrl:"https://gitee.com/dotnetchina/Furion/tree/v4/handbook/docs/saas.mdx",tags:[],version:"current",lastUpdatedBy:"\u767e\u5c0f\u50e7",lastUpdatedAt:1699721618,formattedLastUpdatedAt:"Nov 11, 2023",frontMatter:{id:"saas",title:"11. SaaS \u591a\u79df\u6237",sidebar_label:"11. SaaS \u591a\u79df\u6237"},sidebar:"docs",previous:{title:"10.3 MongoDB \u64cd\u4f5c",permalink:"/docs/mongodb"},next:{title:"12. \u4f9d\u8d56\u6ce8\u5165/\u63a7\u5236\u53cd\u8f6c",permalink:"/docs/dependency-injection"}},d={},l=[{value:"11.1 \u4ec0\u4e48\u662f SaaS",id:"111-\u4ec0\u4e48\u662f-saas",level:2},{value:"11.2 \u4ec0\u4e48\u662f\u591a\u79df\u6237",id:"112-\u4ec0\u4e48\u662f\u591a\u79df\u6237",level:2},{value:"11.3 \u5b9e\u73b0\u591a\u79df\u6237\u65b9\u6848",id:"113-\u5b9e\u73b0\u591a\u79df\u6237\u65b9\u6848",level:2},{value:"11.3.1 \u72ec\u7acb\u6570\u636e\u5e93(\u57fa\u4e8e Database \u7684\u65b9\u5f0f)",id:"1131-\u72ec\u7acb\u6570\u636e\u5e93\u57fa\u4e8e-database-\u7684\u65b9\u5f0f",level:3},{value:"11.3.2 \u5171\u4eab\u6570\u636e\u5e93\uff0c\u72ec\u7acb Schema (\u57fa\u4e8e Schema \u7684\u65b9\u5f0f)",id:"1132-\u5171\u4eab\u6570\u636e\u5e93\u72ec\u7acb-schema-\u57fa\u4e8e-schema-\u7684\u65b9\u5f0f",level:3},{value:"11.3.3 \u5171\u4eab\u6570\u636e\u8868\uff0c\u5171\u4eab Schema (\u57fa\u4e8e TenantId \u7684\u65b9\u5f0f)",id:"1133-\u5171\u4eab\u6570\u636e\u8868\u5171\u4eab-schema-\u57fa\u4e8e-tenantid-\u7684\u65b9\u5f0f",level:3},{value:"11.4 \u591a\u79df\u6237\u4f7f\u7528\u65b9\u6848",id:"114-\u591a\u79df\u6237\u4f7f\u7528\u65b9\u6848",level:2},{value:"11.5 \u57fa\u4e8e TenantId \u7684\u65b9\u5f0f",id:"115-\u57fa\u4e8e-tenantid-\u7684\u65b9\u5f0f",level:2},{value:"11.5.1 \u521b\u5efa\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",id:"1151-\u521b\u5efa\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",level:3},{value:"11.5.2 \u6ce8\u518c\u591a\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",id:"1152-\u6ce8\u518c\u591a\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",level:3},{value:"11.5.3 \u6dfb\u52a0 Tenant \u79cd\u5b50\u6570\u636e",id:"1153-\u6dfb\u52a0-tenant-\u79cd\u5b50\u6570\u636e",level:3},{value:"11.5.4 \u6839\u636e\u6a21\u578b\u521b\u5efa Tenant \u8868",id:"1154-\u6839\u636e\u6a21\u578b\u521b\u5efa-tenant-\u8868",level:3},{value:"11.5.5 \u5b9e\u73b0 IMultiTenantOnTable \u63a5\u53e3",id:"1155-\u5b9e\u73b0-imultitenantontable-\u63a5\u53e3",level:3},{value:"11.5.6 \u5b9e\u73b0 IModelBuilderFilter \u63a5\u53e3",id:"1156-\u5b9e\u73b0-imodelbuilderfilter-\u63a5\u53e3",level:3},{value:"11.5.7 \u91cd\u5199 SavingChangesEvent \u4e8b\u4ef6\u65b9\u6cd5",id:"1157-\u91cd\u5199-savingchangesevent-\u4e8b\u4ef6\u65b9\u6cd5",level:3},{value:"11.6 \u57fa\u4e8e Database \u7684\u65b9\u5f0f",id:"116-\u57fa\u4e8e-database-\u7684\u65b9\u5f0f",level:2},{value:"11.6.1 \u521b\u5efa\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",id:"1161-\u521b\u5efa\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",level:3},{value:"11.6.2 \u6ce8\u518c\u591a\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",id:"1162-\u6ce8\u518c\u591a\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",level:3},{value:"11.6.3 \u6dfb\u52a0 Tenant \u79cd\u5b50\u6570\u636e",id:"1163-\u6dfb\u52a0-tenant-\u79cd\u5b50\u6570\u636e",level:3},{value:"11.6.4 \u6839\u636e\u6a21\u578b\u521b\u5efa Tenant \u8868",id:"1164-\u6839\u636e\u6a21\u578b\u521b\u5efa-tenant-\u8868",level:3},{value:"11.6.5 \u5b9e\u73b0 IMultiTenantOnDatabase \u63a5\u53e3",id:"1165-\u5b9e\u73b0-imultitenantondatabase-\u63a5\u53e3",level:3},{value:"11.6.6 \u91cd\u5199 OnConfiguring \u65b9\u6cd5",id:"1166-\u91cd\u5199-onconfiguring-\u65b9\u6cd5",level:3},{value:"11.7 \u57fa\u4e8e Schema \u7684\u65b9\u5f0f",id:"117-\u57fa\u4e8e-schema-\u7684\u65b9\u5f0f",level:2},{value:"11.7.1 \u521b\u5efa\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",id:"1171-\u521b\u5efa\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",level:3},{value:"11.7.2 \u6ce8\u518c\u591a\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",id:"1172-\u6ce8\u518c\u591a\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",level:3},{value:"11.7.3 \u6dfb\u52a0 Tenant \u79cd\u5b50\u6570\u636e",id:"1173-\u6dfb\u52a0-tenant-\u79cd\u5b50\u6570\u636e",level:3},{value:"11.7.4 \u6839\u636e\u6a21\u578b\u521b\u5efa Tenant \u8868",id:"1174-\u6839\u636e\u6a21\u578b\u521b\u5efa-tenant-\u8868",level:3},{value:"11.7.5 \u5b9e\u73b0 IMultiTenantOnSchema \u63a5\u53e3",id:"1175-\u5b9e\u73b0-imultitenantonschema-\u63a5\u53e3",level:3},{value:"11.7.6 \u5173\u4e8e Code First \u6570\u636e\u8fc1\u79fb",id:"1176-\u5173\u4e8e-code-first-\u6570\u636e\u8fc1\u79fb",level:3},{value:"11.8 \u81ea\u5b9a\u4e49 Tenant \u7c7b\u578b",id:"118-\u81ea\u5b9a\u4e49-tenant-\u7c7b\u578b",level:2},{value:"11.8.1 \u542f\u52a8\u81ea\u5b9a\u4e49\u591a\u79df\u6237\u7c7b\u578b\u914d\u7f6e",id:"1181-\u542f\u52a8\u81ea\u5b9a\u4e49\u591a\u79df\u6237\u7c7b\u578b\u914d\u7f6e",level:3},{value:"11.8.2 \u81ea\u5b9a\u4e49\u79df\u6237\u7c7b",id:"1182-\u81ea\u5b9a\u4e49\u79df\u6237\u7c7b",level:3},{value:"11.9 \u5237\u65b0\u79df\u6237\u7f13\u5b58",id:"119-\u5237\u65b0\u79df\u6237\u7f13\u5b58",level:2},{value:"11.10 \u53cd\u9988\u4e0e\u5efa\u8bae",id:"1110-\u53cd\u9988\u4e0e\u5efa\u8bae",level:2}];function u(n){const e={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.a)(),...n.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(e.h2,{id:"111-\u4ec0\u4e48\u662f-saas",children:["11.1 \u4ec0\u4e48\u662f ",(0,r.jsx)(e.code,{children:"SaaS"})]}),"\n",(0,r.jsxs)(e.blockquote,{children:["\n",(0,r.jsx)(e.p,{children:"SaaS \u662f Software-as-a-Service\uff08\u8f6f\u4ef6\u5373\u670d\u52a1\uff09\u7684\u7b80\u79f0\uff0c\u968f\u7740\u4e92\u8054\u7f51\u6280\u672f\u7684\u53d1\u5c55\u548c\u5e94\u7528\u8f6f\u4ef6\u7684\u6210\u719f\uff0c \u5728 21 \u4e16\u7eaa\u5f00\u59cb\u5174\u8d77\u7684\u4e00\u79cd\u5b8c\u5168\u521b\u65b0\u7684\u8f6f\u4ef6\u5e94\u7528\u6a21\u5f0f\u3002\u5b83\u4e0e\u201con-demand software\u201d\uff0cthe application service provider(ASP\uff0c\u5e94\u7528\u670d\u52a1\u63d0\u4f9b\u5546)\uff0chosted software(\u6258\u7ba1\u8f6f\u4ef6)\u6240\u5177\u6709\u76f8\u4f3c\u7684\u542b\u4e49\u3002"}),"\n",(0,r.jsx)(e.p,{children:"\u5b83\u662f\u4e00\u79cd\u901a\u8fc7 Internet \u63d0\u4f9b\u8f6f\u4ef6\u7684\u6a21\u5f0f\uff0c\u5382\u5546\u5c06\u5e94\u7528\u8f6f\u4ef6\u7edf\u4e00\u90e8\u7f72\u5728\u81ea\u5df1\u7684\u670d\u52a1\u5668\u4e0a\uff0c\u5ba2\u6237\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u5b9e\u9645\u9700\u6c42\uff0c\u901a\u8fc7\u4e92\u8054\u7f51\u5411\u5382\u5546\u5b9a\u8d2d\u6240\u9700\u7684\u5e94\u7528\u8f6f\u4ef6\u670d\u52a1\uff0c\u6309\u5b9a\u8d2d\u7684\u670d\u52a1\u591a\u5c11\u548c\u65f6\u95f4\u957f\u77ed\u5411\u5382\u5546\u652f\u4ed8\u8d39\u7528\uff0c\u5e76\u901a\u8fc7\u4e92\u8054\u7f51\u83b7\u5f97\u5382\u5546\u63d0\u4f9b\u7684\u670d\u52a1\u3002\u7528\u6237\u4e0d\u7528\u518d\u8d2d\u4e70\u8f6f\u4ef6\uff0c\u800c\u6539\u7528\u5411\u63d0\u4f9b\u5546\u79df\u7528\u57fa\u4e8e Web \u7684\u8f6f\u4ef6\uff0c\u6765\u7ba1\u7406\u4f01\u4e1a\u7ecf\u8425\u6d3b\u52a8\uff0c\u4e14\u65e0\u9700\u5bf9\u8f6f\u4ef6\u8fdb\u884c\u7ef4\u62a4\uff0c\u670d\u52a1\u63d0\u4f9b\u5546\u4f1a\u5168\u6743\u7ba1\u7406\u548c\u7ef4\u62a4\u8f6f\u4ef6\uff0c\u8f6f\u4ef6\u5382\u5546\u5728\u5411\u5ba2\u6237\u63d0\u4f9b\u4e92\u8054\u7f51\u5e94\u7528\u7684\u540c\u65f6\uff0c\u4e5f\u63d0\u4f9b\u8f6f\u4ef6\u7684\u79bb\u7ebf\u64cd\u4f5c\u548c\u672c\u5730\u6570\u636e\u5b58\u50a8\uff0c\u8ba9\u7528\u6237\u968f\u65f6\u968f\u5730\u90fd\u53ef\u4ee5\u4f7f\u7528\u5176\u5b9a\u8d2d\u7684\u8f6f\u4ef6\u548c\u670d\u52a1\u3002"}),"\n",(0,r.jsx)(e.p,{children:"\u5bf9\u4e8e\u8bb8\u591a\u5c0f\u578b\u4f01\u4e1a\u6765\u8bf4\uff0cSaaS \u662f\u91c7\u7528\u5148\u8fdb\u6280\u672f\u7684\u6700\u597d\u9014\u5f84\uff0c\u5b83\u6d88\u9664\u4e86\u4f01\u4e1a\u8d2d\u4e70\u3001\u6784\u5efa\u548c\u7ef4\u62a4\u57fa\u7840\u8bbe\u65bd\u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u9700\u8981\u3002"}),"\n"]}),"\n",(0,r.jsx)(e.h2,{id:"112-\u4ec0\u4e48\u662f\u591a\u79df\u6237",children:"11.2 \u4ec0\u4e48\u662f\u591a\u79df\u6237"}),"\n",(0,r.jsxs)(e.p,{children:["\u591a\u79df\u6237\u6280\u672f\u6216\u79f0\u591a\u91cd\u79df\u8d41\u6280\u672f\uff0c\u7b80\u79f0 ",(0,r.jsx)(e.code,{children:"SaaS"}),"\uff0c\u662f\u4e00\u79cd\u8f6f\u4ef6\u67b6\u6784\u6280\u672f\uff0c\u662f\u5b9e\u73b0\u5982\u4f55\u5728\u591a\u7528\u6237\u73af\u5883\u4e0b\uff08\u6b64\u5904\u7684\u591a\u7528\u6237\u4e00\u822c\u662f\u9762\u5411\u4f01\u4e1a\u7528\u6237\uff09\u5171\u7528\u76f8\u540c\u7684\u7cfb\u7edf\u6216\u7a0b\u5e8f\u7ec4\u4ef6\uff0c\u5e76\u4e14\u53ef\u786e\u4fdd\u5404\u7528\u6237\u95f4\u6570\u636e\u7684\u9694\u79bb\u6027\u3002"]}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.strong,{children:"\u7b80\u5355\u8bb2\uff1a\u5728\u4e00\u53f0\u670d\u52a1\u5668\u4e0a\u8fd0\u884c\u5355\u4e2a\u5e94\u7528\u5b9e\u4f8b\uff0c\u5b83\u4e3a\u591a\u4e2a\u79df\u6237\uff08\u5ba2\u6237\uff09\u63d0\u4f9b\u670d\u52a1\u3002"})," \u4ece\u5b9a\u4e49\u4e2d\u6211\u4eec\u53ef\u4ee5\u7406\u89e3\uff1a\u591a\u79df\u6237\u662f\u4e00\u79cd\u67b6\u6784\uff0c\u76ee\u7684\u662f\u4e3a\u4e86\u8ba9\u591a\u7528\u6237\u73af\u5883\u4e0b\u4f7f\u7528\u540c\u4e00\u5957\u7a0b\u5e8f\uff0c\u4e14\u4fdd\u8bc1\u7528\u6237\u95f4\u6570\u636e\u9694\u79bb\u3002\u90a3\u4e48\u91cd\u70b9\u5c31\u5f88\u6d45\u663e\u6613\u61c2\u4e86\uff0c\u591a\u79df\u6237\u7684\u91cd\u70b9\u5c31\u662f\u540c\u4e00\u5957\u7a0b\u5e8f\u4e0b\u5b9e\u73b0\u591a\u7528\u6237\u6570\u636e\u7684\u9694\u79bb\u3002"]}),"\n",(0,r.jsx)(e.h2,{id:"113-\u5b9e\u73b0\u591a\u79df\u6237\u65b9\u6848",children:"11.3 \u5b9e\u73b0\u591a\u79df\u6237\u65b9\u6848"}),"\n",(0,r.jsxs)(e.h3,{id:"1131-\u72ec\u7acb\u6570\u636e\u5e93\u57fa\u4e8e-database-\u7684\u65b9\u5f0f",children:["11.3.1 \u72ec\u7acb\u6570\u636e\u5e93(\u57fa\u4e8e ",(0,r.jsx)(e.code,{children:"Database"})," \u7684\u65b9\u5f0f)"]}),"\n",(0,r.jsx)(e.p,{children:"\u8fd9\u662f\u7b2c\u4e00\u79cd\u65b9\u6848\uff0c\u5373\u4e00\u4e2a\u79df\u6237\u4e00\u4e2a\u6570\u636e\u5e93\uff0c\u8fd9\u79cd\u65b9\u6848\u7684\u7528\u6237\u6570\u636e\u9694\u79bb\u7ea7\u522b\u6700\u9ad8\uff0c\u5b89\u5168\u6027\u6700\u597d\uff0c\u4f46\u6210\u672c\u8f83\u9ad8\u3002"}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:["\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.strong,{children:"\u4f18\u70b9\uff1a"}),"\r\n\u4e3a\u4e0d\u540c\u7684\u79df\u6237\u63d0\u4f9b\u72ec\u7acb\u7684\u6570\u636e\u5e93\uff0c\u6709\u52a9\u4e8e\u7b80\u5316\u6570\u636e\u6a21\u578b\u7684\u6269\u5c55\u8bbe\u8ba1\uff0c\u6ee1\u8db3\u4e0d\u540c\u79df\u6237\u7684\u72ec\u7279\u9700\u6c42\uff1b\u5982\u679c\u51fa\u73b0\u6545\u969c\uff0c\u6062\u590d\u6570\u636e\u6bd4\u8f83\u7b80\u5355\u3002"]}),"\n"]}),"\n",(0,r.jsxs)(e.li,{children:["\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.strong,{children:"\u7f3a\u70b9\uff1a"}),"\r\n\u589e\u591a\u4e86\u6570\u636e\u5e93\u7684\u5b89\u88c5\u6570\u91cf\uff0c\u968f\u4e4b\u5e26\u6765\u7ef4\u62a4\u6210\u672c\u548c\u8d2d\u7f6e\u6210\u672c\u7684\u589e\u52a0\u3002 \u8fd9\u79cd\u65b9\u6848\u4e0e\u4f20\u7edf\u7684\u4e00\u4e2a\u5ba2\u6237\u3001\u4e00\u5957\u6570\u636e\u3001\u4e00\u5957\u90e8\u7f72\u7c7b\u4f3c\uff0c\u5dee\u522b\u53ea\u5728\u4e8e\u8f6f\u4ef6\u7edf\u4e00\u90e8\u7f72\u5728\u8fd0\u8425\u5546\u90a3\u91cc\u3002\u5982\u679c\u9762\u5bf9\u7684\u662f\u94f6\u884c\u3001\u533b\u9662\u7b49\u9700\u8981\u975e\u5e38\u9ad8\u6570\u636e\u9694\u79bb\u7ea7\u522b\u7684\u79df\u6237\uff0c\u53ef\u4ee5\u9009\u62e9\u8fd9\u79cd\u6a21\u5f0f\uff0c\u63d0\u9ad8\u79df\u7528\u7684\u5b9a\u4ef7\u3002\u5982\u679c\u5b9a\u4ef7\u8f83\u4f4e\uff0c\u4ea7\u54c1\u8d70\u4f4e\u4ef7\u8def\u7ebf\uff0c\u8fd9\u79cd\u65b9\u6848\u4e00\u822c\u5bf9\u8fd0\u8425\u5546\u6765\u8bf4\u662f\u65e0\u6cd5\u627f\u53d7\u7684\u3002"]}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(e.h3,{id:"1132-\u5171\u4eab\u6570\u636e\u5e93\u72ec\u7acb-schema-\u57fa\u4e8e-schema-\u7684\u65b9\u5f0f",children:["11.3.2 \u5171\u4eab\u6570\u636e\u5e93\uff0c\u72ec\u7acb ",(0,r.jsx)(e.code,{children:"Schema"})," (\u57fa\u4e8e ",(0,r.jsx)(e.code,{children:"Schema"})," \u7684\u65b9\u5f0f)"]}),"\n",(0,r.jsxs)(e.p,{children:["\u8fd9\u662f\u7b2c\u4e8c\u79cd\u65b9\u6848\uff0c\u5373\u591a\u4e2a\u6216\u6240\u6709\u79df\u6237\u5171\u4eab ",(0,r.jsx)(e.code,{children:"Database"}),"\uff0c\u4f46\u662f\u6bcf\u4e2a\u79df\u6237\u4e00\u4e2a ",(0,r.jsx)(e.code,{children:"Schema"}),"\uff08\u4e5f\u53ef\u53eb\u505a\u4e00\u4e2a user\uff09\u3002\u5e95\u5c42\u5e93\u6bd4\u5982\u662f\uff1a",(0,r.jsx)(e.code,{children:"SqlServer"}),"\u3001",(0,r.jsx)(e.code,{children:"Oracle"})," \u7b49\uff0c\u4e00\u4e2a\u6570\u636e\u5e93\u4e0b\u53ef\u4ee5\u6709\u591a\u4e2a ",(0,r.jsx)(e.code,{children:"Schema"}),"\u3002"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:["\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.strong,{children:"\u4f18\u70b9\uff1a"}),"\r\n\u4e3a\u5b89\u5168\u6027\u8981\u6c42\u8f83\u9ad8\u7684\u79df\u6237\u63d0\u4f9b\u4e86\u4e00\u5b9a\u7a0b\u5ea6\u7684\u903b\u8f91\u6570\u636e\u9694\u79bb\uff0c\u5e76\u4e0d\u662f\u5b8c\u5168\u9694\u79bb\uff1b\u6bcf\u4e2a\u6570\u636e\u5e93\u53ef\u652f\u6301\u66f4\u591a\u7684\u79df\u6237\u6570\u91cf\u3002"]}),"\n"]}),"\n",(0,r.jsxs)(e.li,{children:["\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.strong,{children:"\u7f3a\u70b9\uff1a"}),"\r\n\u5982\u679c\u51fa\u73b0\u6545\u969c\uff0c\u6570\u636e\u6062\u590d\u6bd4\u8f83\u56f0\u96be\uff0c\u56e0\u4e3a\u6062\u590d\u6570\u636e\u5e93\u5c06\u7275\u6d89\u5230\u5176\u4ed6\u79df\u6237\u7684\u6570\u636e\uff1b \u5982\u679c\u9700\u8981\u8de8\u79df\u6237\u7edf\u8ba1\u6570\u636e\uff0c\u5b58\u5728\u4e00\u5b9a\u56f0\u96be\u3002"]}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(e.h3,{id:"1133-\u5171\u4eab\u6570\u636e\u8868\u5171\u4eab-schema-\u57fa\u4e8e-tenantid-\u7684\u65b9\u5f0f",children:["11.3.3 \u5171\u4eab\u6570\u636e\u8868\uff0c\u5171\u4eab ",(0,r.jsx)(e.code,{children:"Schema"})," (\u57fa\u4e8e ",(0,r.jsx)(e.code,{children:"TenantId"})," \u7684\u65b9\u5f0f)"]}),"\n",(0,r.jsxs)(e.p,{children:["\u5171\u4eab\u6570\u636e\u8868 \u8fd9\u662f\u7b2c\u4e09\u79cd\u65b9\u6848\uff0c\u5373\u79df\u6237\u5171\u4eab\u540c\u4e00\u4e2a ",(0,r.jsx)(e.code,{children:"Database"}),"\u3001\u540c\u4e00\u4e2a ",(0,r.jsx)(e.code,{children:"Schema"}),"\uff0c\u4f46\u5728\u8868\u4e2d\u589e\u52a0 ",(0,r.jsx)(e.strong,{children:(0,r.jsx)(e.code,{children:"TenantId"})})," \u591a\u79df\u6237\u7684\u6570\u636e\u5b57\u6bb5\u3002\u8fd9\u662f\u5171\u4eab\u7a0b\u5ea6\u6700\u9ad8\u3001\u9694\u79bb\u7ea7\u522b\u6700\u4f4e\u7684\u6a21\u5f0f\u3002 \u5373\u6bcf\u63d2\u5165\u4e00\u6761\u6570\u636e\u65f6\u90fd\u9700\u8981\u6709\u4e00\u4e2a\u5ba2\u6237\u7684\u6807\u8bc6\u3002\u8fd9\u6837\u624d\u80fd\u5728\u540c\u4e00\u5f20\u8868\u4e2d\u533a\u5206\u51fa\u4e0d\u540c\u5ba2\u6237\u7684\u6570\u636e\u3002"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:["\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.strong,{children:"\u4f18\u70b9\uff1a"}),"\r\n\u4e09\u79cd\u65b9\u6848\u6bd4\u8f83\uff0c\u7b2c\u4e09\u79cd\u65b9\u6848\u7684\u7ef4\u62a4\u548c\u8d2d\u7f6e\u6210\u672c\u6700\u4f4e\uff0c\u5141\u8bb8\u6bcf\u4e2a\u6570\u636e\u5e93\u652f\u6301\u7684\u79df\u6237\u6570\u91cf\u6700\u591a\u3002"]}),"\n"]}),"\n",(0,r.jsxs)(e.li,{children:["\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.strong,{children:"\u7f3a\u70b9\uff1a"}),"\r\n\u9694\u79bb\u7ea7\u522b\u6700\u4f4e\uff0c\u5b89\u5168\u6027\u6700\u4f4e\uff0c\u9700\u8981\u5728\u8bbe\u8ba1\u5f00\u53d1\u65f6\u52a0\u5927\u5bf9\u5b89\u5168\u7684\u5f00\u53d1\u91cf\uff1b \u6570\u636e\u5907\u4efd\u548c\u6062\u590d\u6700\u56f0\u96be\uff0c\u9700\u8981\u9010\u8868\u9010\u6761\u5907\u4efd\u548c\u8fd8\u539f\u3002"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(e.h2,{id:"114-\u591a\u79df\u6237\u4f7f\u7528\u65b9\u6848",children:"11.4 \u591a\u79df\u6237\u4f7f\u7528\u65b9\u6848"}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"Furion"})," \u6846\u67b6\u652f\u6301\u4ee5\u4e0a\u4e09\u79cd\u591a\u79df\u6237\u5b9e\u73b0\u65b9\u6848\uff0c\u4f7f\u7528\u7b80\u5355\u4e14\u5bb9\u6613\u7ef4\u62a4\u3002\u4e0b\u9762\u5206\u522b\u4f7f\u7528\u4e09\u79cd\u4e0d\u540c\u65b9\u5f0f\u6f14\u793a\u591a\u79df\u6237\u65b9\u6848\u7528\u6cd5\u3002"]}),"\n",(0,r.jsx)(e.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"important",children:(0,r.jsxs)(e.p,{children:["\u4e00\u65e6 ",(0,r.jsx)(e.code,{children:"\u6570\u636e\u5e93\u4e0a\u4e0b\u6587"})," \u7c7b\u7ee7\u627f\u4e86\u79df\u6237\u4efb\u610f\u63a5\u53e3\uff0c\u5219\u81ea\u52a8\u5f00\u59cb\u591a\u79df\u6237\u529f\u80fd\u652f\u6301\u3002"]})}),"\n",(0,r.jsxs)(e.h2,{id:"115-\u57fa\u4e8e-tenantid-\u7684\u65b9\u5f0f",children:["11.5 \u57fa\u4e8e ",(0,r.jsx)(e.code,{children:"TenantId"})," \u7684\u65b9\u5f0f"]}),"\n",(0,r.jsx)(e.p,{children:"\u6b64\u65b9\u5f0f\u5728\u4e2d\u5c0f\u578b\u4f01\u4e1a\u7cfb\u7edf\u4e2d\u6700\u4e3a\u5e38\u7528\uff0c\u7ef4\u62a4\u6210\u672c\u4f4e\uff0c\u8d2d\u7f6e\u6210\u672c\u4f4e\u3002"}),"\n",(0,r.jsx)(e.h3,{id:"1151-\u521b\u5efa\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",children:"11.5.1 \u521b\u5efa\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:'showLineNumbers {6-7} title="Furion.EntityFramework.Core\\DbContexts\\MultiTenantDbContext.cs"',children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n [AppDbContext("Sqlite3ConnectionString", DbProvider.Sqlite)]\r\n public class MultiTenantDbContext : AppDbContext\r\n {\r\n public MultiTenantDbContext(DbContextOptions options) : base(options)\r\n {\r\n }\r\n }\r\n}\n'})}),"\n",(0,r.jsx)(e.admonition,{title:"\u7279\u522b\u6ce8\u610f",type:"important",children:(0,r.jsxs)(e.p,{children:["\u591a\u79df\u6237\u64cd\u4f5c\u5efa\u8bae\u5355\u72ec\u4e00\u4e2a\u6570\u636e\u5e93\u4e0a\u4e0b\u6587\uff0c\u800c\u4e14\u9700\u6307\u5b9a ",(0,r.jsx)(e.code,{children:"MultiTenantDbContextLocator"})," \u6570\u636e\u5e93\u4e0a\u4e0b\u6587\u5b9a\u4f4d\u5668\u3002"]})}),"\n",(0,r.jsx)(e.h3,{id:"1152-\u6ce8\u518c\u591a\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",children:"11.5.2 \u6ce8\u518c\u591a\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {14}",children:"using Furion.DatabaseAccessor;\r\nusing Microsoft.Extensions.DependencyInjection;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n [AppStartup(600)]\r\n public sealed class FurEntityFrameworkCoreStartup : AppStartup\r\n {\r\n public void ConfigureServices(IServiceCollection services)\r\n {\r\n services.AddDatabaseAccessor(options =>\r\n {\r\n options.AddDbPool();\r\n options.AddDbPool();\r\n });\r\n }\r\n }\r\n}\n"})}),"\n",(0,r.jsxs)(e.h3,{id:"1153-\u6dfb\u52a0-tenant-\u79cd\u5b50\u6570\u636e",children:["11.5.3 \u6dfb\u52a0 ",(0,r.jsx)(e.code,{children:"Tenant"})," \u79cd\u5b50\u6570\u636e"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:'showLineNumbers {8,12-28} title="Furion.EntityFramework.Core\\SeedDatas\\TenantSeedData.cs"',children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\nusing System;\r\nusing System.Collections.Generic;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n public class TenantSeedData : IEntitySeedData\r\n {\r\n public IEnumerable HasData(DbContext dbContext, Type dbContextLocator)\r\n {\r\n return new List\r\n {\r\n new Tenant\r\n {\r\n TenantId = Guid.Parse("383AFB88-F519-FFF8-B364-6D563BF3687F"),\r\n Name = "\u9ed8\u8ba4\u79df\u6237",\r\n Host = "localhost:44313",\r\n CreatedTime = DateTime.Parse("2020-10-06 20:19:07")\r\n },\r\n new Tenant\r\n {\r\n TenantId = Guid.Parse("C5798CB6-16D6-0F42-EB56-59C695353BC0"),\r\n Name = "\u5176\u4ed6\u79df\u6237",\r\n Host = "localhost:5000",\r\n CreatedTime = DateTime.Parse("2020-10-06 20:20:32")\r\n }\r\n };\r\n }\r\n }\r\n}\n'})}),"\n",(0,r.jsx)(e.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"note",children:(0,r.jsxs)(e.p,{children:["\u8be5\u6b65\u9aa4\u53ea\u5728 ",(0,r.jsx)(e.code,{children:"Code First"})," \u65b9\u5f0f\u6267\u884c\uff0c",(0,r.jsx)(e.code,{children:"Database First"})," \u65e0\u9700\u914d\u7f6e\u79cd\u5b50\u6570\u636e\u3002"]})}),"\n",(0,r.jsxs)(e.h3,{id:"1154-\u6839\u636e\u6a21\u578b\u521b\u5efa-tenant-\u8868",children:["11.5.4 \u6839\u636e\u6a21\u578b\u521b\u5efa ",(0,r.jsx)(e.code,{children:"Tenant"})," \u8868"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-shell",metastring:"showLineNumbers ",children:"Add-Migration add_tenant_table -Context MultiTenantDbContext\n"})}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-shell",metastring:"showLineNumbers ",children:"Update-Database -Context MultiTenantDbContext\n"})}),"\n",(0,r.jsxs)(e.h3,{id:"1155-\u5b9e\u73b0-imultitenantontable-\u63a5\u53e3",children:["11.5.5 \u5b9e\u73b0 ",(0,r.jsx)(e.code,{children:"IMultiTenantOnTable"})," \u63a5\u53e3"]}),"\n",(0,r.jsxs)(e.p,{children:["\u5728\u9700\u8981\u591a\u79df\u6237\u7684\u6570\u636e\u5e93\u4e0a\u4e0b\u6587\u4e2d\u5b9e\u73b0 ",(0,r.jsx)(e.code,{children:"IMultiTenantOnTable"})," \u63a5\u53e3\uff0c\u5982\uff1a"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {8,14-17}",children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\nusing System;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n [AppDbContext("Sqlite3ConnectionString", DbProvider.Sqlite)]\r\n public class FurionDbContext : AppDbContext, IMultiTenantOnTable, IModelBuilderFilter\r\n {\r\n public FurionDbContext(DbContextOptions options) : base(options)\r\n {\r\n }\r\n\r\n public object GetTenantId()\r\n {\r\n return base.Tenant?.TenantId ?? Guid.Empty;\r\n }\r\n }\r\n}\n'})}),"\n",(0,r.jsxs)(e.p,{children:["\u5728 ",(0,r.jsx)(e.code,{children:"GetTenantId()"})," \u65b9\u6cd5\u4e2d\uff0c\u9996\u5148\u83b7\u53d6\u8bf7\u6c42\u7684 ",(0,r.jsx)(e.code,{children:"\u4e3b\u673a\u5730\u5740"}),"\uff0c\u7136\u540e\u6839\u636e\u4e3b\u673a\u5730\u5740\u67e5\u8be2\u5bf9\u5e94\u7684\u79df\u6237 ",(0,r.jsx)(e.code,{children:"TenantId"}),"\uff0c\u907f\u514d\u591a\u6b21\u67e5\u8be2\u6570\u636e\u5e93\uff0c\u8fd9\u91cc\u4f7f\u7528\u4e86 ",(0,r.jsx)(e.code,{children:"IMemoryCache"})," \u5185\u5b58\u7f13\u5b58\u3002"]}),"\n",(0,r.jsxs)(e.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"important",children:[(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"base.Tenant"})," \u53ea\u662f ",(0,r.jsx)(e.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u7684\u9ed8\u8ba4\u79df\u6237\u5b9e\u73b0\u65b9\u6cd5\uff0c\u5982\u679c\u4e0d\u80fd\u6ee1\u8db3\u4e1a\u52a1\u9700\u6c42\uff0c\u53ea\u9700\u8981\u5728 ",(0,r.jsx)(e.code,{children:"GetTenantId"})," \u91cc\u9762\u5199\u4f60\u7684\u4e1a\u52a1\u4ee3\u7801\u5373\u53ef\uff0c\u4e5f\u5c31\u662f\u65e0\u9700\u8c03\u7528 ",(0,r.jsx)(e.code,{children:"base.Tenant"}),"\u3002\u5982\uff1a"]}),(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers ",children:"public object GetTenantId()\r\n{\r\n // \u8fd9\u91cc\u662f\u4f60\u83b7\u53d6 TenantId \u7684\u903b\u8f91\r\n return \u4f60\u7684 TenantId;\r\n}\n"})})]}),"\n",(0,r.jsxs)(e.h3,{id:"1156-\u5b9e\u73b0-imodelbuilderfilter-\u63a5\u53e3",children:["11.5.6 \u5b9e\u73b0 ",(0,r.jsx)(e.code,{children:"IModelBuilderFilter"})," \u63a5\u53e3"]}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"IModelBuilderFilter"})," \u63a5\u53e3\u662f\u5168\u5c40\u67e5\u8be2\u8fc7\u6ee4\u5668\u5b9e\u73b0\u63a5\u53e3\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u914d\u7f6e\u5b9e\u4f53 ",(0,r.jsx)(e.code,{children:"TenantId"})," \u8fc7\u6ee4\u5668"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {9,20-23}",children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\nusing Microsoft.EntityFrameworkCore.Metadata.Builders;\r\nusing System;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n [AppDbContext("Sqlite3ConnectionString", DbProvider.Sqlite)]\r\n public class FurionDbContext : AppDbContext, IMultiTenantOnTable, IModelBuilderFilter\r\n {\r\n public FurionDbContext(DbContextOptions options) : base(options)\r\n {\r\n }\r\n\r\n public object GetTenantId()\r\n {\r\n return base.Tenant?.TenantId ?? Guid.Empty;\r\n }\r\n\r\n public void OnCreating(ModelBuilder modelBuilder, EntityTypeBuilder entityBuilder, DbContext dbContext, Type dbContextLocator)\r\n {\r\n entityBuilder.HasQueryFilter(BuildTenantQueryFilter(entityBuilder, dbContext));\r\n }\r\n }\r\n}\n'})}),"\n",(0,r.jsxs)(e.h3,{id:"1157-\u91cd\u5199-savingchangesevent-\u4e8b\u4ef6\u65b9\u6cd5",children:["11.5.7 \u91cd\u5199 ",(0,r.jsx)(e.code,{children:"SavingChangesEvent"})," \u4e8b\u4ef6\u65b9\u6cd5"]}),"\n",(0,r.jsxs)(e.p,{children:["\u901a\u8fc7\u4e0a\u9762\u7684\u6b65\u9aa4\uff0c\u6211\u4eec\u5df2\u7ecf\u89e3\u51b3\u4e86 ",(0,r.jsx)(e.code,{children:"\u67e5\u8be2"})," \u79df\u6237\u8fc7\u6ee4\u529f\u80fd\uff0c\u4f46\u662f ",(0,r.jsx)(e.code,{children:"\u65b0\u589e"})," \u548c ",(0,r.jsx)(e.code,{children:"\u66f4\u65b0"})," \u8fd8\u672a\u5904\u7406\u3002"]}),"\n",(0,r.jsxs)(e.ul,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"\u65b0\u589e"})," \u6570\u636e\u7684\u65f6\u5019\u81ea\u52a8\u8bbe\u7f6e ",(0,r.jsx)(e.code,{children:"TenantId"})," \u7684\u503c"]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"\u66f4\u65b0"})," \u6570\u636e\u7684\u65f6\u5019\u6392\u9664 ",(0,r.jsx)(e.code,{children:"TenantId"})," \u5c5e\u6027\u66f4\u65b0"]}),"\n"]}),"\n",(0,r.jsxs)(e.p,{children:["\u5b9e\u73b0\u4e0a\u9762\u7684\u6b65\u9aa4\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u8981\u91cd\u5199 ",(0,r.jsx)(e.code,{children:"SavingChangesEvent"})," \u4e8b\u4ef6\u65b9\u6cd5\u5373\u53ef\u3002"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {26-48}",children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\nusing Microsoft.EntityFrameworkCore.Metadata.Builders;\r\nusing System;\r\nusing System.Linq;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n [AppDbContext("Sqlite3ConnectionString", DbProvider.Sqlite)]\r\n public class FurionDbContext : AppDbContext, IMultiTenantOnTable, IModelBuilderFilter\r\n {\r\n public FurionDbContext(DbContextOptions options) : base(options)\r\n {\r\n }\r\n\r\n public object GetTenantId()\r\n {\r\n return base.Tenant?.TenantId ?? Guid.Empty;\r\n }\r\n\r\n public void OnCreating(ModelBuilder modelBuilder, EntityTypeBuilder entityBuilder, DbContext dbContext, Type dbContextLocator)\r\n {\r\n entityBuilder.HasQueryFilter(BuildTenantQueryFilter(entityBuilder, dbContext));\r\n }\r\n\r\n protected override void SavingChangesEvent(DbContextEventData eventData, InterceptionResult result)\r\n {\r\n // \u83b7\u53d6\u5f53\u524d\u4e8b\u4ef6\u5bf9\u5e94\u4e0a\u4e0b\u6587\r\n var dbContext = eventData.Context;\r\n\r\n // \u83b7\u53d6\u6240\u6709\u65b0\u589e\u3001\u66f4\u65b0\u3001\u5220\u9664\u7684\u5b9e\u4f53\r\n var entities = dbContext.ChangeTracker.Entries().Where(u => u.State == EntityState.Added || u.State == EntityState.Modified || u.State == EntityState.Deleted);\r\n\r\n foreach (var entity in entities)\r\n { \r\n switch (entity.State)\r\n {\r\n // \u81ea\u52a8\u8bbe\u7f6e\u79df\u6237Id\r\n case EntityState.Added:\r\n entity.Property(nameof(Entity.TenantId)).CurrentValue = GetTenantId();\r\n break;\r\n // \u6392\u9664\u79df\u6237Id\r\n case EntityState.Modified:\r\n entity.Property(nameof(Entity.TenantId)).IsModified = false;\r\n break;\r\n // \u5220\u9664\u5904\u7406\r\n case EntityState.Deleted:\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n}\n'})}),"\n",(0,r.jsx)("img",{src:(0,s.Z)("img/saas1.png")}),"\n",(0,r.jsxs)(e.h2,{id:"116-\u57fa\u4e8e-database-\u7684\u65b9\u5f0f",children:["11.6 \u57fa\u4e8e ",(0,r.jsx)(e.code,{children:"Database"})," \u7684\u65b9\u5f0f"]}),"\n",(0,r.jsx)(e.p,{children:"\u6b64\u65b9\u5f0f\u5728\u4e2d\u5927\u578b\u4f01\u4e1a\u7cfb\u7edf\u4e2d\u6700\u4e3a\u5e38\u7528\uff0c\u4e00\u4e2a\u79df\u6237\uff08\u5ba2\u6237\uff09\u4e00\u4e2a\u72ec\u7acb\u7684\u6570\u636e\u5e93\u3002"}),"\n",(0,r.jsx)(e.h3,{id:"1161-\u521b\u5efa\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",children:"11.6.1 \u521b\u5efa\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:'showLineNumbers {6-7} title="Furion.EntityFramework.Core\\DbContexts\\MultiTenantDbContext.cs"',children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n [AppDbContext("Sqlite3ConnectionString", DbProvider.Sqlite)]\r\n public class MultiTenantDbContext : AppDbContext\r\n {\r\n public MultiTenantDbContext(DbContextOptions options) : base(options)\r\n {\r\n }\r\n }\r\n}\n'})}),"\n",(0,r.jsx)(e.admonition,{title:"\u7279\u522b\u6ce8\u610f",type:"important",children:(0,r.jsxs)(e.p,{children:["\u591a\u79df\u6237\u64cd\u4f5c\u5efa\u8bae\u5355\u72ec\u4e00\u4e2a\u6570\u636e\u5e93\u4e0a\u4e0b\u6587\uff0c\u800c\u4e14\u9700\u6307\u5b9a ",(0,r.jsx)(e.code,{children:"MultiTenantDbContextLocator"})," \u6570\u636e\u5e93\u4e0a\u4e0b\u6587\u5b9a\u4f4d\u5668\u3002"]})}),"\n",(0,r.jsx)(e.h3,{id:"1162-\u6ce8\u518c\u591a\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",children:"11.6.2 \u6ce8\u518c\u591a\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {13,14}",children:"using Furion.DatabaseAccessor;\r\nusing Microsoft.Extensions.DependencyInjection;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n [AppStartup(600)]\r\n public sealed class FurEntityFrameworkCoreStartup : AppStartup\r\n {\r\n public void ConfigureServices(IServiceCollection services)\r\n {\r\n services.AddDatabaseAccessor(options =>\r\n {\r\n options.AddDb();\r\n options.AddDbPool();\r\n });\r\n }\r\n }\r\n}\n"})}),"\n",(0,r.jsx)(e.admonition,{title:"\u7279\u522b\u6ce8\u610f",type:"caution",children:(0,r.jsxs)(e.p,{children:["\u9700\u8981 ",(0,r.jsx)(e.code,{children:"Database"})," \u591a\u79df\u6237\u65b9\u6848\u7684\u6570\u636e\u5e93\u4e0a\u4e0b\u6587\u9700\u8981\u91c7\u7528 ",(0,r.jsx)(e.code,{children:"AddDb"})," \u6ce8\u518c\uff0c\u800c\u4e0d\u662f ",(0,r.jsx)(e.code,{children:"AddDbPool"}),"\u3002\u539f\u56e0\u662f ",(0,r.jsx)(e.code,{children:"AddDbPool"})," \u65b9\u5f0f\u6ce8\u518c\u540e\u7eed\u4e0d\u652f\u6301 ",(0,r.jsx)(e.code,{children:"OnConfiguring"})," \u91cd\u5199\uff01\uff01\uff01"]})}),"\n",(0,r.jsxs)(e.h3,{id:"1163-\u6dfb\u52a0-tenant-\u79cd\u5b50\u6570\u636e",children:["11.6.3 \u6dfb\u52a0 ",(0,r.jsx)(e.code,{children:"Tenant"})," \u79cd\u5b50\u6570\u636e"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:'showLineNumbers {8,12-30} title="Furion.EntityFramework.Core\\SeedDatas\\TenantSeedData.cs"',children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\nusing System;\r\nusing System.Collections.Generic;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n public class TenantSeedData : IEntitySeedData\r\n {\r\n public IEnumerable HasData(DbContext dbContext, Type dbContextLocator)\r\n {\r\n return new List\r\n {\r\n new Tenant\r\n {\r\n TenantId = Guid.Parse("383AFB88-F519-FFF8-B364-6D563BF3687F"),\r\n Name = "\u9ed8\u8ba4\u79df\u6237",\r\n Host = "localhost:44313",\r\n CreatedTime = DateTime.Parse("2020-10-06 20:19:07"),\r\n ConnectionString = "Data Source=./Furion.db" // \u914d\u7f6e\u8fde\u63a5\u5b57\u7b26\u4e32\r\n },\r\n new Tenant\r\n {\r\n TenantId = Guid.Parse("C5798CB6-16D6-0F42-EB56-59C695353BC0"),\r\n Name = "\u5176\u4ed6\u79df\u6237",\r\n Host = "localhost:5000",\r\n CreatedTime = DateTime.Parse("2020-10-06 20:20:32"),\r\n ConnectionString = "Data Source=./Fur2.db" // \u914d\u7f6e\u8fde\u63a5\u5b57\u7b26\u4e32\r\n }\r\n };\r\n }\r\n }\r\n}\n'})}),"\n",(0,r.jsx)(e.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"note",children:(0,r.jsxs)(e.p,{children:["\u8be5\u6b65\u9aa4\u53ea\u5728 ",(0,r.jsx)(e.code,{children:"Code First"})," \u65b9\u5f0f\u6267\u884c\uff0c",(0,r.jsx)(e.code,{children:"Database First"})," \u65e0\u9700\u914d\u7f6e\u79cd\u5b50\u6570\u636e\u3002"]})}),"\n",(0,r.jsxs)(e.h3,{id:"1164-\u6839\u636e\u6a21\u578b\u521b\u5efa-tenant-\u8868",children:["11.6.4 \u6839\u636e\u6a21\u578b\u521b\u5efa ",(0,r.jsx)(e.code,{children:"Tenant"})," \u8868"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-shell",metastring:"showLineNumbers ",children:"Add-Migration add_tenant_table -Context MultiTenantDbContext\n"})}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-shell",metastring:"showLineNumbers ",children:"Update-Database -Context MultiTenantDbContext\n"})}),"\n",(0,r.jsxs)(e.h3,{id:"1165-\u5b9e\u73b0-imultitenantondatabase-\u63a5\u53e3",children:["11.6.5 \u5b9e\u73b0 ",(0,r.jsx)(e.code,{children:"IMultiTenantOnDatabase"})," \u63a5\u53e3"]}),"\n",(0,r.jsxs)(e.p,{children:["\u5728\u9700\u8981\u591a\u79df\u6237\u7684\u6570\u636e\u5e93\u4e0a\u4e0b\u6587\u4e2d\u5b9e\u73b0 ",(0,r.jsx)(e.code,{children:"IMultiTenantOnDatabase"})," \u63a5\u53e3\uff0c\u5982\uff1a"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {6,13-16}",children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n // \u8fd9\u91cc\u53ef\u4e0d\u914d\u7f6e\r\n public class FurionDbContext : AppDbContext, IMultiTenantOnDatabase\r\n {\r\n public FurionDbContext(DbContextOptions options) : base(options)\r\n {\r\n }\r\n\r\n public string GetDatabaseConnectionString()\r\n {\r\n return base.Tenant?.ConnectionString??"\u9ed8\u8ba4\u94fe\u63a5\u5b57\u7b26\u4e32";\r\n }\r\n }\r\n}\n'})}),"\n",(0,r.jsxs)(e.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"important",children:[(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"base.Tenant"})," \u53ea\u662f ",(0,r.jsx)(e.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u7684\u9ed8\u8ba4\u79df\u6237\u5b9e\u73b0\u65b9\u6cd5\uff0c\u5982\u679c\u4e0d\u80fd\u6ee1\u8db3\u4e1a\u52a1\u9700\u6c42\uff0c\u53ea\u9700\u8981\u5728 ",(0,r.jsx)(e.code,{children:"GetDatabaseConnectionString"})," \u91cc\u9762\u5199\u4f60\u7684\u4e1a\u52a1\u4ee3\u7801\u5373\u53ef\uff0c\u4e5f\u5c31\u662f\u65e0\u9700\u8c03\u7528 ",(0,r.jsx)(e.code,{children:"base.Tenant"}),"\u3002\u5982\uff1a"]}),(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers ",children:"public string GetDatabaseConnectionString()\r\n{\r\n // \u8fd9\u91cc\u662f\u4f60\u83b7\u53d6 DatabaseConnecionString \u7684\u903b\u8f91\r\n return \u4f60\u7684 \u8fde\u63a5\u5b57\u7b26\u4e32;\r\n}\n"})})]}),"\n",(0,r.jsxs)(e.h3,{id:"1166-\u91cd\u5199-onconfiguring-\u65b9\u6cd5",children:["11.6.6 \u91cd\u5199 ",(0,r.jsx)(e.code,{children:"OnConfiguring"})," \u65b9\u6cd5"]}),"\n",(0,r.jsxs)(e.p,{children:["\u5728\u9700\u8981\u591a\u79df\u6237\u7684\u6570\u636e\u5e93\u4e0a\u4e0b\u6587\u4e2d\u91cd\u5199 ",(0,r.jsx)(e.code,{children:"OnConfiguring"})," \u65b9\u6cd5\u5e76\u914d\u7f6e\u8fde\u63a5\u5b57\u7b26\u4e32\uff1a"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {12-17}",children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n public class FurionDbContext : AppDbContext, IMultiTenantOnDatabase\r\n {\r\n public FurionDbContext(DbContextOptions options) : base(options)\r\n {\r\n }\r\n\r\n protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)\r\n {\r\n optionsBuilder.UseSqlite(GetDatabaseConnectionString());\r\n\r\n base.OnConfiguring(optionsBuilder);\r\n }\r\n\r\n public string GetDatabaseConnectionString()\r\n {\r\n return base.Tenant?.ConnectionString??"\u9ed8\u8ba4\u94fe\u63a5\u5b57\u7b26\u4e32";\r\n }\r\n }\r\n}\n'})}),"\n",(0,r.jsx)("img",{src:(0,s.Z)("img/saas2.png")}),"\n",(0,r.jsxs)(e.admonition,{title:"\u7279\u522b\u6ce8\u610f",type:"caution",children:[(0,r.jsxs)(e.p,{children:["\u57fa\u4e8e ",(0,r.jsx)(e.code,{children:"Database"})," \u65b9\u5f0f\u505a ",(0,r.jsx)(e.code,{children:"Code First"})," \u7684\u65f6\u5019\uff0c\u9700\u8981\u624b\u52a8\u6307\u5b9a\u8fc1\u79fb\u7a0b\u5e8f\u540d\u79f0\uff0c\u5982\uff1a"]}),(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers ",children:'optionsBuilder.UseSqlite(GetDatabaseConnectionString(), options=>\r\n{\r\n options.MigrationsAssembly("My.Migrations");\r\n});\n'})})]}),"\n",(0,r.jsxs)(e.h2,{id:"117-\u57fa\u4e8e-schema-\u7684\u65b9\u5f0f",children:["11.7 \u57fa\u4e8e ",(0,r.jsx)(e.code,{children:"Schema"})," \u7684\u65b9\u5f0f"]}),"\n",(0,r.jsxs)(e.p,{children:["\u6b64\u65b9\u5f0f\u5728\u4e2d\u5c0f\u578b\u4f01\u4e1a\u7cfb\u7edf\u4e2d\u4e5f\u4e0d\u5c11\u89c1\uff0c\u4e00\u4e2a\u79df\u6237\uff08\u5ba2\u6237\uff09\u5171\u4eab\u6570\u636e\u5e93\u4e14\u4e0d\u540c ",(0,r.jsx)(e.code,{children:"Schema"}),"\u3002"]}),"\n",(0,r.jsx)(e.h3,{id:"1171-\u521b\u5efa\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",children:"11.7.1 \u521b\u5efa\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:'showLineNumbers {6-7} title="Furion.EntityFramework.Core\\DbContexts\\MultiTenantDbContext.cs"',children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n [AppDbContext("Sqlite3ConnectionString", DbProvider.Sqlite)]\r\n public class MultiTenantDbContext : AppDbContext\r\n {\r\n public MultiTenantDbContext(DbContextOptions options) : base(options)\r\n {\r\n }\r\n }\r\n}\n'})}),"\n",(0,r.jsx)(e.admonition,{title:"\u7279\u522b\u6ce8\u610f",type:"important",children:(0,r.jsxs)(e.p,{children:["\u591a\u79df\u6237\u64cd\u4f5c\u5efa\u8bae\u5355\u72ec\u4e00\u4e2a\u6570\u636e\u5e93\u4e0a\u4e0b\u6587\uff0c\u800c\u4e14\u9700\u6307\u5b9a ",(0,r.jsx)(e.code,{children:"MultiTenantDbContextLocator"})," \u6570\u636e\u5e93\u4e0a\u4e0b\u6587\u5b9a\u4f4d\u5668\u3002"]})}),"\n",(0,r.jsx)(e.h3,{id:"1172-\u6ce8\u518c\u591a\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587",children:"11.7.2 \u6ce8\u518c\u591a\u79df\u6237\u6570\u636e\u5e93\u4e0a\u4e0b\u6587"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {14}",children:"using Furion.DatabaseAccessor;\r\nusing Microsoft.Extensions.DependencyInjection;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n [AppStartup(600)]\r\n public sealed class FurEntityFrameworkCoreStartup : AppStartup\r\n {\r\n public void ConfigureServices(IServiceCollection services)\r\n {\r\n services.AddDatabaseAccessor(options =>\r\n {\r\n options.AddDbPool();\r\n options.AddDbPool();\r\n });\r\n }\r\n }\r\n}\n"})}),"\n",(0,r.jsxs)(e.h3,{id:"1173-\u6dfb\u52a0-tenant-\u79cd\u5b50\u6570\u636e",children:["11.7.3 \u6dfb\u52a0 ",(0,r.jsx)(e.code,{children:"Tenant"})," \u79cd\u5b50\u6570\u636e"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:'showLineNumbers {8,12-30} title="Furion.EntityFramework.Core\\SeedDatas\\TenantSeedData.cs"',children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\nusing System;\r\nusing System.Collections.Generic;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n public class TenantSeedData : IEntitySeedData\r\n {\r\n public IEnumerable HasData(DbContext dbContext, Type dbContextLocator)\r\n {\r\n return new List\r\n {\r\n new Tenant\r\n {\r\n TenantId = Guid.Parse("383AFB88-F519-FFF8-B364-6D563BF3687F"),\r\n Name = "\u9ed8\u8ba4\u79df\u6237",\r\n Host = "localhost:44313",\r\n CreatedTime = DateTime.Parse("2020-10-06 20:19:07"),\r\n Schema = "dbo" // Schema\r\n },\r\n new Tenant\r\n {\r\n TenantId = Guid.Parse("C5798CB6-16D6-0F42-EB56-59C695353BC0"),\r\n Name = "\u5176\u4ed6\u79df\u6237",\r\n Host = "localhost:5000",\r\n CreatedTime = DateTime.Parse("2020-10-06 20:20:32"),\r\n Schema = "furion" // Schema\r\n }\r\n };\r\n }\r\n }\r\n}\n'})}),"\n",(0,r.jsx)(e.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"note",children:(0,r.jsxs)(e.p,{children:["\u8be5\u6b65\u9aa4\u53ea\u5728 ",(0,r.jsx)(e.code,{children:"Code First"})," \u65b9\u5f0f\u6267\u884c\uff0c",(0,r.jsx)(e.code,{children:"Database First"})," \u65e0\u9700\u914d\u7f6e\u79cd\u5b50\u6570\u636e\u3002"]})}),"\n",(0,r.jsxs)(e.h3,{id:"1174-\u6839\u636e\u6a21\u578b\u521b\u5efa-tenant-\u8868",children:["11.7.4 \u6839\u636e\u6a21\u578b\u521b\u5efa ",(0,r.jsx)(e.code,{children:"Tenant"})," \u8868"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-shell",metastring:"showLineNumbers ",children:"Add-Migration add_tenant_table -Context MultiTenantDbContext\n"})}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-shell",metastring:"showLineNumbers ",children:"Update-Database -Context MultiTenantDbContext\n"})}),"\n",(0,r.jsxs)(e.h3,{id:"1175-\u5b9e\u73b0-imultitenantonschema-\u63a5\u53e3",children:["11.7.5 \u5b9e\u73b0 ",(0,r.jsx)(e.code,{children:"IMultiTenantOnSchema"})," \u63a5\u53e3"]}),"\n",(0,r.jsxs)(e.p,{children:["\u5728\u9700\u8981\u591a\u79df\u6237\u7684\u6570\u636e\u5e93\u4e0a\u4e0b\u6587\u4e2d\u5b9e\u73b0 ",(0,r.jsx)(e.code,{children:"IMultiTenantOnSchema"})," \u63a5\u53e3\uff0c\u5982\uff1a"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {6,12-15}",children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n [AppDbContext("Sqlite3ConnectionString", DbProvider.Sqlite)]\r\n public class FurionDbContext : AppDbContext, IMultiTenantOnSchema\r\n {\r\n public FurionDbContext(DbContextOptions options) : base(options)\r\n {\r\n }\r\n\r\n public string GetSchemaName()\r\n {\r\n return base.Tenant?.Schema??"dbo";\r\n }\r\n }\r\n}\n'})}),"\n",(0,r.jsxs)(e.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"important",children:[(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"base.Tenant"})," \u53ea\u662f ",(0,r.jsx)(e.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u7684\u9ed8\u8ba4\u79df\u6237\u5b9e\u73b0\u65b9\u6cd5\uff0c\u5982\u679c\u4e0d\u80fd\u6ee1\u8db3\u4e1a\u52a1\u9700\u6c42\uff0c\u53ea\u9700\u8981\u5728 ",(0,r.jsx)(e.code,{children:"GetSchemaName"})," \u91cc\u9762\u5199\u4f60\u7684\u4e1a\u52a1\u4ee3\u7801\u5373\u53ef\uff0c\u4e5f\u5c31\u662f\u65e0\u9700\u8c03\u7528 ",(0,r.jsx)(e.code,{children:"base.Tenant"}),"\u3002\u5982\uff1a"]}),(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers ",children:"public string GetSchemaName()\r\n{\r\n // \u8fd9\u91cc\u662f\u4f60\u83b7\u53d6 Schema \u7684\u903b\u8f91\r\n return \u4f60\u7684 Schema;\r\n}\n"})})]}),"\n",(0,r.jsxs)(e.h3,{id:"1176-\u5173\u4e8e-code-first-\u6570\u636e\u8fc1\u79fb",children:["11.7.6 \u5173\u4e8e ",(0,r.jsx)(e.code,{children:"Code First \u6570\u636e\u8fc1\u79fb"})]}),"\n",(0,r.jsxs)(e.p,{children:["\u57fa\u4e8e ",(0,r.jsx)(e.code,{children:"Schema"})," \u65b9\u5f0f\u6bd4\u8f83\u7279\u522b\uff0c\u751f\u6210\u6570\u636e\u8fc1\u79fb\u7684\u65f6\u5019\u6ca1\u529e\u6cd5\u83b7\u53d6\u79df\u6237\u4fe1\u606f\uff0c\u6240\u4ee5\u5efa\u8bae",(0,r.jsx)(e.strong,{children:"\u5206\u5f00\u591a\u6b21\u8fc1\u79fb"}),"\uff0c\u5982\uff1a"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers ",children:'public string GetSchemaName()\r\n{\r\n return base.Tenant?.Schema?? "\u79df\u6237\u4e00Schema";\r\n}\n'})}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers ",children:'public string GetSchemaName()\r\n{\r\n return base.Tenant?.Schema?? "\u79df\u6237\u4e8cSchema";\r\n}\n'})}),"\n",(0,r.jsx)(e.p,{children:"\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u8fc1\u79fb\u7684\u65f6\u5019\u751f\u6210\u591a\u6b21\u8fc1\u79fb\u4e86\u3002"}),"\n",(0,r.jsxs)(e.h2,{id:"118-\u81ea\u5b9a\u4e49-tenant-\u7c7b\u578b",children:["11.8 \u81ea\u5b9a\u4e49 ",(0,r.jsx)(e.code,{children:"Tenant"})," \u7c7b\u578b"]}),"\n",(0,r.jsxs)(e.p,{children:["\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c",(0,r.jsx)(e.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684 ",(0,r.jsx)(e.code,{children:"Tenant"})," \u7c7b\u578b\uff0c\u65b9\u4fbf\u5927\u5bb6\u5feb\u901f\u5b9e\u73b0 ",(0,r.jsx)(e.code,{children:"SaaS"})," \u591a\u79df\u6237\u529f\u80fd\uff0c\u5982\u679c\u9700\u8981\u81ea\u5b9a\u4e49\u591a\u79df\u6237 ",(0,r.jsx)(e.code,{children:"Tenant"})," \u7c7b\u578b\uff0c\u53ea\u9700\u8981\u542f\u7528\u4ee5\u4e0b\u914d\u7f6e\u5373\u53ef\uff1a"]}),"\n",(0,r.jsx)(e.h3,{id:"1181-\u542f\u52a8\u81ea\u5b9a\u4e49\u591a\u79df\u6237\u7c7b\u578b\u914d\u7f6e",children:"11.8.1 \u542f\u52a8\u81ea\u5b9a\u4e49\u591a\u79df\u6237\u7c7b\u578b\u914d\u7f6e"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {3}",children:"services.AddDatabaseAccessor(options =>\r\n{\r\n options.CustomizeMultiTenants(); // \u542f\u7528\u81ea\u5b9a\u4e49\u591a\u79df\u6237\u7c7b\u578b\uff0c\u6709\u4e00\u4e2a\u9ed8\u8ba4\u53c2\u6570\uff0c\u914d\u7f6e\u591a\u79df\u6237\u8868\u5b57\u6bb5\u540d\r\n options.AddDbPool();\r\n});\n"})}),"\n",(0,r.jsx)(e.h3,{id:"1182-\u81ea\u5b9a\u4e49\u79df\u6237\u7c7b",children:"11.8.2 \u81ea\u5b9a\u4e49\u79df\u6237\u7c7b"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers {6}",children:"using System;\r\nusing System.ComponentModel.DataAnnotations.Schema;\r\n\r\nnamespace Furion.Core\r\n{\r\n public class MyTenant : IEntity\r\n {\r\n [Key]\r\n public Guid TenantId { get; set; }\r\n\r\n public string Name { get; set; }\r\n\r\n public string Host { get; set; }\r\n }\r\n}\n"})}),"\n",(0,r.jsx)(e.p,{children:"\u5982\u679c\u9700\u8981\u67e5\u8be2\u8be5\u79df\u6237\u4fe1\u606f\uff0c\u53ef\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u83b7\u53d6\uff0c\u5982\uff1a"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers ",children:"var tenantDbContext = Db.GetDbContext();\r\nvar myTenant = tenantDbContext.Set();\n"})}),"\n",(0,r.jsx)(e.h2,{id:"119-\u5237\u65b0\u79df\u6237\u7f13\u5b58",children:"11.9 \u5237\u65b0\u79df\u6237\u7f13\u5b58"}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"Furion"})," \u6846\u67b6\u4f1a\u5728\u79df\u6237\u4e0a\u4e0b\u6587\u7b2c\u4e00\u6b21\u67e5\u8be2\u65f6\u5019\u5c06\u79df\u6237\u8868\u7f13\u5b58\u8d77\u6765\uff0c\u907f\u514d\u9891\u53d1\u67e5\u8be2\u6570\u636e\u5e93\uff0c\u5982\u679c\u66f4\u65b0\u4e86\u79df\u6237\u8868\uff0c\u5219\u9700\u8981\u624b\u52a8\u5237\u65b0\u79df\u6237\u4fe1\u606f\uff0c\u5982\uff1a"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{className:"language-cs",metastring:"showLineNumbers ",children:"using Furion.DatabaseAccessor.Extensions;\r\n\r\n// \u5728\u66f4\u65b0\u79df\u6237\u4fe1\u606f\u540e\u8c03\u7528\r\n_repository.Context.RefreshTenantCache();\n"})}),"\n",(0,r.jsx)(e.h2,{id:"1110-\u53cd\u9988\u4e0e\u5efa\u8bae",children:"11.10 \u53cd\u9988\u4e0e\u5efa\u8bae"}),"\n",(0,r.jsx)(e.admonition,{title:"\u4e0e\u6211\u4eec\u4ea4\u6d41",type:"note",children:(0,r.jsxs)(e.p,{children:["\u7ed9 Furion \u63d0 ",(0,r.jsx)(e.a,{href:"https://gitee.com/dotnetchina/Furion/issues/new?issue",children:"Issue"}),"\u3002"]})})]})}function h(n={}){const{wrapper:e}={...(0,i.a)(),...n.components};return e?(0,r.jsx)(e,{...n,children:(0,r.jsx)(u,{...n})}):u(n)}},1151:(n,e,t)=>{t.d(e,{Z:()=>o,a:()=>a});var r=t(7294);const i={},s=r.createContext(i);function a(n){const e=r.useContext(s);return r.useMemo((function(){return"function"==typeof n?n(e):{...e,...n}}),[e,n])}function o(n){let e;return e=n.disableParentContext?"function"==typeof n.components?n.components(i):n.components||i:a(n.components),r.createElement(s.Provider,{value:e},n.children)}}}]);