"use strict";(self.webpackChunkfurion=self.webpackChunkfurion||[]).push([[2574],{7107:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>o,contentTitle:()=>d,default:()=>h,frontMatter:()=>t,metadata:()=>c,toc:()=>a});var s=r(5893),i=r(1151),l=r(4996);const t={id:"dbcontext-function",title:"9.15 \u51fd\u6570\u64cd\u4f5c",sidebar_label:"9.15 \u51fd\u6570\u64cd\u4f5c"},d=void 0,c={id:"dbcontext-function",title:"9.15 \u51fd\u6570\u64cd\u4f5c",description:"\u63a8\u8350\u4f7f\u7528 \u300a9.18 Sql \u9ad8\u7ea7\u4ee3\u7406\u300b\u4ee3\u66ff\u672c\u7ae0\u8282\u529f\u80fd\u3002Sql \u9ad8\u7ea7\u4ee3\u7406 \u80fd\u591f\u63d0\u4f9b\u66f4\u5bb9\u6613\u4e14\u66f4\u6613\u7ef4\u62a4\u7684\u65b9\u5f0f\u3002",source:"@site/docs/dbcontext-function.mdx",sourceDirName:".",slug:"/dbcontext-function",permalink:"/docs/dbcontext-function",draft:!1,unlisted:!1,editUrl:"https://gitee.com/dotnetchina/Furion/tree/v4/handbook/docs/dbcontext-function.mdx",tags:[],version:"current",lastUpdatedBy:"MonkSoul",lastUpdatedAt:1682389320,formattedLastUpdatedAt:"Apr 25, 2023",frontMatter:{id:"dbcontext-function",title:"9.15 \u51fd\u6570\u64cd\u4f5c",sidebar_label:"9.15 \u51fd\u6570\u64cd\u4f5c"},sidebar:"docs",previous:{title:"9.14 \u5b58\u50a8\u8fc7\u7a0b\u64cd\u4f5c",permalink:"/docs/dbcontext-proc"},next:{title:"9.16 Sql \u64cd\u4f5c",permalink:"/docs/dbcontext-sql"}},o={},a=[{value:"9.15.1 \u6570\u636e\u5e93\u51fd\u6570",id:"9151-\u6570\u636e\u5e93\u51fd\u6570",level:2},{value:"9.15.1.1 \u652f\u6301\u6807\u91cf\u51fd\u6570\u7684\u6570\u636e\u5e93",id:"91511-\u652f\u6301\u6807\u91cf\u51fd\u6570\u7684\u6570\u636e\u5e93",level:3},{value:"9.15.1.2 \u652f\u6301\u8868\u503c\u51fd\u6570\u7684\u6570\u636e\u5e93",id:"91512-\u652f\u6301\u8868\u503c\u51fd\u6570\u7684\u6570\u636e\u5e93",level:3},{value:"9.15.2 \u6570\u636e\u5e93\u51fd\u6570\u7c7b\u578b",id:"9152-\u6570\u636e\u5e93\u51fd\u6570\u7c7b\u578b",level:2},{value:"9.15.3 \u51fd\u6570\u7684\u4f7f\u7528",id:"9153-\u51fd\u6570\u7684\u4f7f\u7528",level:2},{value:"9.15.3.1 \u6807\u91cf\u51fd\u6570\u8fd4\u56de object",id:"91531-\u6807\u91cf\u51fd\u6570\u8fd4\u56de-object",level:3},{value:"9.15.3.2 \u6807\u91cf\u51fd\u6570\u8fd4\u56de T",id:"91532-\u6807\u91cf\u51fd\u6570\u8fd4\u56de-t",level:3},{value:"9.15.3.3 \u8868\u503c\u51fd\u6570\u8fd4\u56de DataTable",id:"91533-\u8868\u503c\u51fd\u6570\u8fd4\u56de-datatable",level:3},{value:"9.15.3.4 \u8868\u503c\u51fd\u6570\u8fd4\u56de List<T>",id:"91534-\u8868\u503c\u51fd\u6570\u8fd4\u56de-listt",level:3},{value:"9.15.4 \u5728 Linq \u4e2d\u4f7f\u7528 \u6807\u91cf\u51fd\u6570",id:"9154-\u5728-linq-\u4e2d\u4f7f\u7528-\u6807\u91cf\u51fd\u6570",level:2},{value:"9.15.4.1 \u521b\u5efa\u6807\u91cf\u51fd\u6570",id:"91541-\u521b\u5efa\u6807\u91cf\u51fd\u6570",level:3},{value:"9.15.4.2 \u521b\u5efa\u9759\u6001\u7c7b\u548c\u9759\u6001\u65b9\u6cd5",id:"91542-\u521b\u5efa\u9759\u6001\u7c7b\u548c\u9759\u6001\u65b9\u6cd5",level:3},{value:"9.15.4.3 \u5728 Linq \u4e2d\u4f7f\u7528",id:"91543-\u5728-linq-\u4e2d\u4f7f\u7528",level:3},{value:"9.15.5 \u5728 Linq \u4e2d\u4f7f\u7528 \u8868\u503c\u51fd\u6570",id:"9155-\u5728-linq-\u4e2d\u4f7f\u7528-\u8868\u503c\u51fd\u6570",level:2},{value:"9.15.5.1 \u521b\u5efa\u8868\u503c\u51fd\u6570",id:"91551-\u521b\u5efa\u8868\u503c\u51fd\u6570",level:3},{value:"9.15.5.2 \u521b\u5efa\u8868\u503c\u51fd\u6570\u6a21\u578b",id:"91552-\u521b\u5efa\u8868\u503c\u51fd\u6570\u6a21\u578b",level:3},{value:"9.15.5.3 \u8868\u503c\u51fd\u6570\u914d\u7f6e",id:"91553-\u8868\u503c\u51fd\u6570\u914d\u7f6e",level:3},{value:"9.15.5.4 \u5728 Linq \u4e2d\u4f7f\u7528",id:"91554-\u5728-linq-\u4e2d\u4f7f\u7528",level:3},{value:"9.15.6 \u5728 EF Core \u5185\u7f6e\u51fd\u6570",id:"9156-\u5728-ef-core-\u5185\u7f6e\u51fd\u6570",level:2},{value:"9.15.7 \u53cd\u9988\u4e0e\u5efa\u8bae",id:"9157-\u53cd\u9988\u4e0e\u5efa\u8bae",level:2}];function u(e){const n={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.admonition,{title:"\u6e29\u99a8\u63d0\u793a",type:"important",children:(0,s.jsxs)(n.p,{children:["\u63a8\u8350\u4f7f\u7528 \u300a",(0,s.jsx)(n.a,{href:"/docs/dbcontext-sql-proxy",children:"9.18 Sql \u9ad8\u7ea7\u4ee3\u7406"}),"\u300b\u4ee3\u66ff\u672c\u7ae0\u8282\u529f\u80fd\u3002",(0,s.jsx)(n.code,{children:"Sql \u9ad8\u7ea7\u4ee3\u7406"})," \u80fd\u591f\u63d0\u4f9b\u66f4\u5bb9\u6613\u4e14\u66f4\u6613\u7ef4\u62a4\u7684\u65b9\u5f0f\u3002"]})}),"\n","\n","\n",(0,s.jsx)(n.h2,{id:"9151-\u6570\u636e\u5e93\u51fd\u6570",children:"9.15.1 \u6570\u636e\u5e93\u51fd\u6570"}),"\n",(0,s.jsx)(n.p,{children:"\u5f15\u7528\u767e\u5ea6\u767e\u79d1\uff1a"}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsx)(n.p,{children:"\u6570\u636e\u5e93\u51fd\u6570\u662f\u6307\u5f53\u9700\u8981\u5206\u6790\u6570\u636e\u6e05\u5355\u4e2d\u7684\u6570\u503c\u662f\u5426\u7b26\u5408\u7279\u5b9a\u6761\u4ef6\u65f6\uff0c\u4f7f\u7528\u6570\u636e\u5e93\u5de5\u4f5c\u8868\u51fd\u6570\u3002"}),"\n"]}),"\n",(0,s.jsxs)(n.p,{children:["\u7b80\u5355\u6765\u8bf4\uff0c\u6570\u636e\u5e93\u51fd\u6570\u5c31\u662f\u7528\u4e8e\u5b50\u8ba1\u7b97\u7684\u51fd\u6570\u3002\u5176\u8ba1\u7b97\u7684\u7ed3\u679c\u53ef\u4ee5\u7528\u4e8e\u6784\u5efa ",(0,s.jsx)(n.code,{children:"sql"})," \u8bed\u53e5\u3002"]}),"\n",(0,s.jsx)(n.h3,{id:"91511-\u652f\u6301\u6807\u91cf\u51fd\u6570\u7684\u6570\u636e\u5e93",children:"9.15.1.1 \u652f\u6301\u6807\u91cf\u51fd\u6570\u7684\u6570\u636e\u5e93"}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"SqlServer"}),(0,s.jsx)(n.th,{children:"Sqlite"}),(0,s.jsx)(n.th,{children:"Cosmos"}),(0,s.jsx)(n.th,{children:"InMemoryDatabase"}),(0,s.jsx)(n.th,{children:"MySql"}),(0,s.jsx)(n.th,{children:"PostgreSQL"}),(0,s.jsx)(n.th,{children:"Oracle"}),(0,s.jsx)(n.th,{children:"Firebird"}),(0,s.jsx)(n.th,{children:"Dm"})]})}),(0,s.jsx)(n.tbody,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"\u2714"}),(0,s.jsx)(n.td,{}),(0,s.jsx)(n.td,{children:"\u2714"}),(0,s.jsx)(n.td,{}),(0,s.jsx)(n.td,{children:"\u2714"}),(0,s.jsx)(n.td,{children:"\u2714"}),(0,s.jsx)(n.td,{children:"\u2714"}),(0,s.jsx)(n.td,{}),(0,s.jsx)(n.td,{})]})})]}),"\n",(0,s.jsx)(n.h3,{id:"91512-\u652f\u6301\u8868\u503c\u51fd\u6570\u7684\u6570\u636e\u5e93",children:"9.15.1.2 \u652f\u6301\u8868\u503c\u51fd\u6570\u7684\u6570\u636e\u5e93"}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"SqlServer"}),(0,s.jsx)(n.th,{children:"Sqlite"}),(0,s.jsx)(n.th,{children:"Cosmos"}),(0,s.jsx)(n.th,{children:"InMemoryDatabase"}),(0,s.jsx)(n.th,{children:"MySql"}),(0,s.jsx)(n.th,{children:"PostgreSQL"}),(0,s.jsx)(n.th,{children:"Oracle"}),(0,s.jsx)(n.th,{children:"Firebird"}),(0,s.jsx)(n.th,{children:"Dm"})]})}),(0,s.jsx)(n.tbody,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"\u2714"}),(0,s.jsx)(n.td,{}),(0,s.jsx)(n.td,{children:"\u2714"}),(0,s.jsx)(n.td,{}),(0,s.jsx)(n.td,{}),(0,s.jsx)(n.td,{children:"\u2714"}),(0,s.jsx)(n.td,{children:"\u2714"}),(0,s.jsx)(n.td,{}),(0,s.jsx)(n.td,{})]})})]}),"\n",(0,s.jsx)(n.h2,{id:"9152-\u6570\u636e\u5e93\u51fd\u6570\u7c7b\u578b",children:"9.15.2 \u6570\u636e\u5e93\u51fd\u6570\u7c7b\u578b"}),"\n",(0,s.jsx)(n.p,{children:"\u5728\u5173\u7cfb\u578b\u6570\u636e\u5e93\u4e2d\uff0c\u6570\u636e\u5e93\u51fd\u6570\u6709\u8fd9\u4e24\u79cd\u7c7b\u578b\uff1a"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"\u6807\u91cf\u51fd\u6570"}),"\uff1a\u53ea\u80fd\u8fd4\u56de\u5355\u4e2a\u503c"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"\u8868\u503c\u51fd\u6570"}),"\uff1a\u53ea\u80fd\u8fd4\u56de\u4e00\u4e2a\u7ed3\u679c\u96c6"]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"9153-\u51fd\u6570\u7684\u4f7f\u7528",children:"9.15.3 \u51fd\u6570\u7684\u4f7f\u7528"}),"\n",(0,s.jsxs)(n.h3,{id:"91531-\u6807\u91cf\u51fd\u6570\u8fd4\u56de-object",children:["9.15.3.1 \u6807\u91cf\u51fd\u6570\u8fd4\u56de ",(0,s.jsx)(n.code,{children:"object"})]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'// ISqlRepository \u65b9\u6cd5\r\nvar value = _sqlRepository.SqlFunctionScalar("func_GetValue");\r\n\r\n// ISqlDispatchProxy \u65b9\u5f0f\r\nvar value = _sqlExecuteProxy.GetValue(); // \u63a8\u8350\u65b9\u5f0f\r\n\r\n// \u5b9e\u4f53\u4ed3\u50a8\u65b9\u5f0f\r\nvar value = _personRepository.SqlFunctionScalar("func_GetValue");\r\n\r\n// IRepository \u975e\u6cdb\u578b\u65b9\u5f0f\r\nvar value = _repository.Sql().SqlFunctionScalar("func_GetValue");\r\n\r\n// \u53d8\u6001\u61d2\u4eba\u65b9\u5f0f\uff0c\u76f4\u63a5\u901a\u8fc7\u51fd\u6570\u540d\u6267\u884c\r\nvar value = "func_GetValue".SqlFunctionScalar();\n'})}),"\n",(0,s.jsx)(n.admonition,{title:"\u5173\u4e8e\u5f02\u6b65",type:"note",children:(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u6bcf\u4e00\u4e2a\u6570\u636e\u5e93\u64cd\u4f5c\u90fd\u652f\u6301\u5f02\u6b65\u65b9\u5f0f\uff0c\u7531\u4e8e\u7bc7\u5e45\u6709\u9650\uff0c\u5c31\u4e0d\u5217\u4e3e\u5f02\u6b65\u65b9\u5f0f\u4e86\u3002"]})}),"\n",(0,s.jsxs)(n.h3,{id:"91532-\u6807\u91cf\u51fd\u6570\u8fd4\u56de-t",children:["9.15.3.2 \u6807\u91cf\u51fd\u6570\u8fd4\u56de ",(0,s.jsx)(n.code,{children:"T"})]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'// ISqlRepository \u65b9\u6cd5\r\nvar value = _sqlRepository.SqlFunctionScalar("func_GetValue");\r\n\r\n// ISqlDispatchProxy \u65b9\u5f0f\r\nvar value = _sqlExecuteProxy.GetValue(); // \u63a8\u8350\u65b9\u5f0f\r\n\r\n// \u5b9e\u4f53\u4ed3\u50a8\u65b9\u5f0f\r\nvar value = _personRepository.SqlFunctionScalar("func_GetValue");\r\n\r\n// IRepository \u975e\u6cdb\u578b\u65b9\u5f0f\r\nvar value = _repository.Sql().SqlFunctionScalar("func_GetValue");\r\n\r\n// \u53d8\u6001\u61d2\u4eba\u65b9\u5f0f\uff0c\u76f4\u63a5\u901a\u8fc7\u51fd\u6570\u540d\u6267\u884c\r\nvar value = "func_GetValue".SqlFunctionScalar();\n'})}),"\n",(0,s.jsx)(n.admonition,{title:"\u5173\u4e8e\u5f02\u6b65",type:"note",children:(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u6bcf\u4e00\u4e2a\u6570\u636e\u5e93\u64cd\u4f5c\u90fd\u652f\u6301\u5f02\u6b65\u65b9\u5f0f\uff0c\u7531\u4e8e\u7bc7\u5e45\u6709\u9650\uff0c\u5c31\u4e0d\u5217\u4e3e\u5f02\u6b65\u65b9\u5f0f\u4e86\u3002"]})}),"\n",(0,s.jsxs)(n.h3,{id:"91533-\u8868\u503c\u51fd\u6570\u8fd4\u56de-datatable",children:["9.15.3.3 \u8868\u503c\u51fd\u6570\u8fd4\u56de ",(0,s.jsx)(n.code,{children:"DataTable"})]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'// ISqlRepository \u65b9\u6cd5\r\nvar value = _sqlRepository.SqlFunctionQuery("func_GetTable");\r\n\r\n// ISqlDispatchProxy \u65b9\u5f0f\r\nvar value = _sqlExecuteProxy.GetTable(); // \u63a8\u8350\u65b9\u5f0f\r\n\r\n// \u5b9e\u4f53\u4ed3\u50a8\u65b9\u5f0f\r\nvar value = _personRepository.SqlFunctionQuery("func_GetTable");\r\n\r\n// IRepository \u975e\u6cdb\u578b\u65b9\u5f0f\r\nvar value = _repository.Sql().SqlFunctionQuery("func_GetTable");\r\n\r\n// \u53d8\u6001\u61d2\u4eba\u65b9\u5f0f\uff0c\u76f4\u63a5\u901a\u8fc7\u51fd\u6570\u540d\u6267\u884c\r\nvar value = "func_GetTable".SqlFunctionQuery();\n'})}),"\n",(0,s.jsx)(n.admonition,{title:"\u5173\u4e8e\u5f02\u6b65",type:"note",children:(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u6bcf\u4e00\u4e2a\u6570\u636e\u5e93\u64cd\u4f5c\u90fd\u652f\u6301\u5f02\u6b65\u65b9\u5f0f\uff0c\u7531\u4e8e\u7bc7\u5e45\u6709\u9650\uff0c\u5c31\u4e0d\u5217\u4e3e\u5f02\u6b65\u65b9\u5f0f\u4e86\u3002"]})}),"\n",(0,s.jsxs)(n.h3,{id:"91534-\u8868\u503c\u51fd\u6570\u8fd4\u56de-listt",children:["9.15.3.4 \u8868\u503c\u51fd\u6570\u8fd4\u56de ",(0,s.jsx)(n.code,{children:"List"})]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'// ISqlRepository \u65b9\u6cd5\r\nvar value = _sqlRepository.SqlFunctionQuery("func_GetTable");\r\n\r\n// ISqlDispatchProxy \u65b9\u5f0f\r\nvar value = _sqlExecuteProxy.GetTable(); // \u63a8\u8350\u65b9\u5f0f\r\n\r\n// \u5b9e\u4f53\u4ed3\u50a8\u65b9\u5f0f\r\nvar value = _personRepository.SqlFunctionQuery("func_GetTable");\r\n\r\n// IRepository \u975e\u6cdb\u578b\u65b9\u5f0f\r\nvar value = _repository.Sql().SqlFunctionQuery("func_GetTable");\r\n\r\n// \u53d8\u6001\u61d2\u4eba\u65b9\u5f0f\uff0c\u76f4\u63a5\u901a\u8fc7\u51fd\u6570\u540d\u6267\u884c\r\nvar value = "func_GetTable".SqlFunctionQuery();\n'})}),"\n",(0,s.jsx)(n.admonition,{title:"\u5173\u4e8e\u5f02\u6b65",type:"note",children:(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u6bcf\u4e00\u4e2a\u6570\u636e\u5e93\u64cd\u4f5c\u90fd\u652f\u6301\u5f02\u6b65\u65b9\u5f0f\uff0c\u7531\u4e8e\u7bc7\u5e45\u6709\u9650\uff0c\u5c31\u4e0d\u5217\u4e3e\u5f02\u6b65\u65b9\u5f0f\u4e86\u3002"]})}),"\n",(0,s.jsxs)(n.h2,{id:"9154-\u5728-linq-\u4e2d\u4f7f\u7528-\u6807\u91cf\u51fd\u6570",children:["9.15.4 \u5728 ",(0,s.jsx)(n.code,{children:"Linq"})," \u4e2d\u4f7f\u7528 ",(0,s.jsx)(n.code,{children:"\u6807\u91cf\u51fd\u6570"})]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u975e\u5e38\u7075\u6d3b\u7684\u5728 ",(0,s.jsx)(n.code,{children:"Linq"})," \u4e2d\u4f7f\u7528\u6807\u91cf\u51fd\u6570\u7684\u65b9\u6cd5\u3002\u5982\u679c\u50cf\u4f7f\u7528\u8fd9\u6837\u7684\u65b9\u5f0f\uff0c\u9700\u8981\u6ee1\u8db3\u4ee5\u4e0b\u4e24\u4e2a\u6761\u4ef6\uff1a"]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["\u6807\u91cf\u51fd\u6570\u5fc5\u987b\u5b9a\u4e49\u5728",(0,s.jsx)(n.strong,{children:"\u516c\u5f00\u9759\u6001\u7c7b"}),"\u4e2d\uff0c\u4e14\u81ea\u5df1\u4e5f\u662f",(0,s.jsx)(n.strong,{children:"\u516c\u5f00\u9759\u6001\u65b9\u6cd5"})]}),"\n",(0,s.jsxs)(n.li,{children:["\u8be5",(0,s.jsx)(n.strong,{children:"\u516c\u5f00\u9759\u6001\u65b9\u6cd5"}),"\u5fc5\u987b\u8d34\u6709 ",(0,s.jsx)(n.code,{children:"[QueryableFunction]"})," \u7279\u6027"]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"\u793a\u4f8b\u5982\u4e0b\uff1a"}),"\n",(0,s.jsx)(n.h3,{id:"91541-\u521b\u5efa\u6807\u91cf\u51fd\u6570",children:"9.15.4.1 \u521b\u5efa\u6807\u91cf\u51fd\u6570"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sql",metastring:"showLineNumbers",children:"CREATE FUNCTION FN_GetId\r\n(\r\n @id INT\r\n)\r\nRETURNS INT\r\nAS\r\nBEGIN\r\n RETURN @id + 1;\r\nEND;\n"})}),"\n",(0,s.jsx)(n.h3,{id:"91542-\u521b\u5efa\u9759\u6001\u7c7b\u548c\u9759\u6001\u65b9\u6cd5",children:"9.15.4.2 \u521b\u5efa\u9759\u6001\u7c7b\u548c\u9759\u6001\u65b9\u6cd5"}),"\n",(0,s.jsxs)(n.p,{children:["\u521b\u5efa\u9759\u6001\u7c7b\uff0c\u5982 ",(0,s.jsx)(n.code,{children:"QueryFunctions"}),"\uff0c\u5c06\u8be5 ",(0,s.jsx)(n.code,{children:"\u6807\u91cf\u51fd\u6570"})," \u653e\u5728\u9759\u6001\u7c7b\u4e2d\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {1, 7, 10-11}",children:'using Furion.DatabaseAccessor;\r\nusing System;\r\n\r\nnamespace Furion.Application\r\n{\r\n // \u5fc5\u987b\u662f\u516c\u5f00\u9759\u6001\u7684\r\n public static class QueryFunctions\r\n {\r\n // \u5fc5\u987b\u662f\u9759\u6001\u65b9\u6cd5\r\n [QueryableFunction("FN_GetId", "dbo")] // \u914d\u7f6e\u6807\u91cf\u51fd\u6570\r\n public static int GetId(int id) => throw new NotSupportedException();\r\n }\r\n}\n'})}),"\n",(0,s.jsxs)(n.h3,{id:"91543-\u5728-linq-\u4e2d\u4f7f\u7528",children:["9.15.4.3 \u5728 ",(0,s.jsx)(n.code,{children:"Linq"})," \u4e2d\u4f7f\u7528"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"_personRepository.Where(u => u.Id > QueryFunctions.GetId(1)).ToList();\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sql",metastring:"showLineNumbers",children:"SELECT [p].[Id], [p].[Address], [p].[Age], [p].[CreatedTime], [p].[IsDeleted], [p].[Name], [p].[UpdatedTime]\r\nFROM [Person] AS [p]\r\nWHERE [p].[Id] > [dbo].[FN_GetId](1) // \ud83d\udca5 \u6ce8\u610f\u8fd9\u91cc\n"})}),"\n",(0,s.jsx)("img",{src:(0,l.Z)("img/fn1.png")}),"\n",(0,s.jsxs)(n.h2,{id:"9155-\u5728-linq-\u4e2d\u4f7f\u7528-\u8868\u503c\u51fd\u6570",children:["9.15.5 \u5728 ",(0,s.jsx)(n.code,{children:"Linq"})," \u4e2d\u4f7f\u7528 ",(0,s.jsx)(n.code,{children:"\u8868\u503c\u51fd\u6570"})]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"EF Core 5.0"})," \u7248\u672c\u652f\u6301\u5728 ",(0,s.jsx)(n.code,{children:"Linq"})," \u4e2d\u64cd\u4f5c ",(0,s.jsx)(n.code,{children:"\u8868\u503c\u51fd\u6570"}),"\uff0c\u64cd\u4f5c\u6709\u70b9\u7c7b\u4f3c ",(0,s.jsx)(n.code,{children:"\u89c6\u56fe\u64cd\u4f5c"})]}),"\n",(0,s.jsx)(n.p,{children:"\u793a\u4f8b\u5982\u4e0b\uff1a"}),"\n",(0,s.jsx)(n.h3,{id:"91551-\u521b\u5efa\u8868\u503c\u51fd\u6570",children:"9.15.5.1 \u521b\u5efa\u8868\u503c\u51fd\u6570"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sql",metastring:"showLineNumbers",children:"CREATE FUNCTION dbo.GetPersons\r\n(\r\n @id INT\r\n)\r\nRETURNS TABLE\r\nAS\r\nRETURN\r\n(\r\n SELECT Id,\r\n Name,\r\n Age,\r\n Address\r\n FROM dbo.Person\r\n WHERE Id > @id\r\n);\n"})}),"\n",(0,s.jsx)(n.h3,{id:"91552-\u521b\u5efa\u8868\u503c\u51fd\u6570\u6a21\u578b",children:"9.15.5.2 \u521b\u5efa\u8868\u503c\u51fd\u6570\u6a21\u578b"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"namespace Furion.Core\r\n{\r\n public class F_Person\r\n {\r\n /// \r\n /// \u4e3b\u952eId\r\n /// \r\n public int Id { get; set; }\r\n\r\n /// \r\n /// \u59d3\u540d\r\n /// \r\n public string Name { get; set; }\r\n\r\n /// \r\n /// \u5e74\u9f84\r\n /// \r\n public int Age { get; set; }\r\n\r\n /// \r\n /// \u4f4f\u5740\r\n /// \r\n public string Address { get; set; }\r\n }\r\n}\n"})}),"\n",(0,s.jsx)(n.h3,{id:"91553-\u8868\u503c\u51fd\u6570\u914d\u7f6e",children:"9.15.5.3 \u8868\u503c\u51fd\u6570\u914d\u7f6e"}),"\n",(0,s.jsxs)(n.p,{children:["\u5728 ",(0,s.jsx)(n.code,{children:"DbContext"})," \u7c7b\u4e2d\u5b9a\u4e49\u65b9\u6cd5\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {3,10,20-21}",children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\nusing System.Linq;\r\n\r\nnamespace Furion.EntityFramework.Core\r\n{\r\n [AppDbContext("Sqlite3ConnectionString")]\r\n public class FurionDbContext : AppDbContext\r\n {\r\n public IQueryable GetPersons(int id) => FromExpression(() => GetPersons(id));\r\n\r\n public FurionDbContext(DbContextOptions options) : base(options)\r\n {\r\n }\r\n\r\n protected override void OnModelCreating(ModelBuilder modelBuilder)\r\n {\r\n base.OnModelCreating(modelBuilder);\r\n\r\n modelBuilder.Entity(typeof(F_Person)).HasNoKey();\r\n modelBuilder.HasDbFunction(() => GetPersons(default));\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsxs)(n.h3,{id:"91554-\u5728-linq-\u4e2d\u4f7f\u7528",children:["9.15.5.4 \u5728 ",(0,s.jsx)(n.code,{children:"Linq"})," \u4e2d\u4f7f\u7528"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'IQueryable query = _repository.DynamicDbContext.GetPersons(1);\r\nvar result = query.Where(u => u.Name.Equals("Furion")).ToList();\n'})}),"\n",(0,s.jsxs)(n.p,{children:["\u6700\u7ec8\u751f\u6210 ",(0,s.jsx)(n.code,{children:"Sql"})]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sql",metastring:"showLineNumbers",children:"SELECT [g].Id, [g].Name, [g].Age, [g].Address\r\nFROM dbo.GetPersons(1) AS [g]\r\nWHERE [g].Name == N'Furion';\n"})}),"\n",(0,s.jsxs)(n.h2,{id:"9156-\u5728-ef-core-\u5185\u7f6e\u51fd\u6570",children:["9.15.6 \u5728 ",(0,s.jsx)(n.code,{children:"EF Core"})," \u5185\u7f6e\u51fd\u6570"]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"EF Core"})," \u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u5f88\u591a\u5e38\u7528\u7684\u5185\u7f6e\u51fd\u6570\uff0c\u53ef\u4ee5\u5728 ",(0,s.jsx)(n.code,{children:"Lambda"})," \u6761\u4ef6\u4e2d\u4f7f\u7528\uff0c\u4e3b\u8981\u662f\u901a\u8fc7 EF.Functions \u8c03\u7528\uff0c\u5982\uff1a"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"_repository.Where(u => EF.Functions.DateDiffHour(u.CreatedDt, DateTime.Now) > 8).FirstOrDefault();\n"})}),"\n",(0,s.jsx)(n.p,{children:"\u8fd9\u4e2a\u8bed\u53e5\u4f7f\u7528\u4e86 EF.Functions.DateDiffHour \u6700\u7ec8\u751f\u6210\u7684 Sql \u5982\u4e0b\uff1a"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sql",metastring:"showLineNumbers",children:"SELECT TOP(1) [a].*\r\nFROM [dbo].[TEST] AS [a]\r\nWHERE DATEDIFF(HOUR, [a].[CREATED_DT], GETDATE()) > 8\n"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"EF Core"})," \u5185\u7f6e\u51fd\u6570\u5c31\u4e0d\u4e00\u4e00\u5217\u51fa\u4e86\uff0c\u53ef\u4ee5\u901a\u8fc7 ",(0,s.jsx)(n.code,{children:"EF.Functions"})," \u67e5\u770b\u66f4\u591a\uff0c\u5982\u679c\u4e0d\u80fd\u6ee1\u8db3\u81ea\u5df1\u7684\u9700\u6c42\uff0c\u90a3\u4e48\u53ef\u4ee5\u81ea\u5b9a\u4e49 ",(0,s.jsx)(n.code,{children:"Linq"})," \u6807\u91cf\u51fd\u6570"]}),"\n",(0,s.jsx)(n.h2,{id:"9157-\u53cd\u9988\u4e0e\u5efa\u8bae",children:"9.15.7 \u53cd\u9988\u4e0e\u5efa\u8bae"}),"\n",(0,s.jsx)(n.admonition,{title:"\u4e0e\u6211\u4eec\u4ea4\u6d41",type:"note",children:(0,s.jsxs)(n.p,{children:["\u7ed9 Furion \u63d0 ",(0,s.jsx)(n.a,{href:"https://gitee.com/dotnetchina/Furion/issues/new?issue",children:"Issue"}),"\u3002"]})})]})}function h(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(u,{...e})}):u(e)}},1151:(e,n,r)=>{r.d(n,{Z:()=>d,a:()=>t});var s=r(7294);const i={},l=s.createContext(i);function t(e){const n=s.useContext(l);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:t(e.components),s.createElement(l.Provider,{value:n},e.children)}}}]);