"use strict";(self.webpackChunkfurion=self.webpackChunkfurion||[]).push([[3021],{514:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>o,contentTitle:()=>a,default:()=>l,frontMatter:()=>u,metadata:()=>d,toc:()=>c});var t=n(5893),s=n(1151);const u={id:"dbcontext-add-or-update",title:"9.8 \u65b0\u589e\u6216\u66f4\u65b0\u64cd\u4f5c",sidebar_label:"9.8 \u65b0\u589e\u6216\u66f4\u65b0\u64cd\u4f5c"},a=void 0,d={id:"dbcontext-add-or-update",title:"9.8 \u65b0\u589e\u6216\u66f4\u65b0\u64cd\u4f5c",description:"\u4ee5\u4e0b\u5185\u5bb9\u5728 Furion 2.5.1 + \u7248\u672c\u4e2d\u5df2\u79fb\u9664\u3002\u6b64\u64cd\u4f5c\u8ba9\u5f88\u591a\u4e0d\u4e86\u89e3 EFCore \u7684\u5f00\u53d1\u8005\u4ea7\u751f\u4e86\u5f88\u5927\u7684\u8bef\u89e3\uff0c\u4e0d\u77e5\u4f55\u65f6\u65b0\u589e\u6216\u4f55\u65f6\u66f4\u65b0\uff0c\u6545\u79fb\u9664\u6b64\u529f\u80fd\u3002",source:"@site/docs/dbcontext-add-or-update.mdx",sourceDirName:".",slug:"/dbcontext-add-or-update",permalink:"/docs/dbcontext-add-or-update",draft:!1,unlisted:!1,editUrl:"https://gitee.com/dotnetchina/Furion/tree/v4/handbook/docs/dbcontext-add-or-update.mdx",tags:[],version:"current",lastUpdatedBy:"MonkSoul",lastUpdatedAt:1682389320,formattedLastUpdatedAt:"Apr 25, 2023",frontMatter:{id:"dbcontext-add-or-update",title:"9.8 \u65b0\u589e\u6216\u66f4\u65b0\u64cd\u4f5c",sidebar_label:"9.8 \u65b0\u589e\u6216\u66f4\u65b0\u64cd\u4f5c"},sidebar:"docs",previous:{title:"9.7 \u66f4\u65b0\u64cd\u4f5c",permalink:"/docs/dbcontext-update"},next:{title:"9.9 \u5220\u9664\u64cd\u4f5c",permalink:"/docs/dbcontext-delete"}},o={},c=[{value:"9.8.1 \u65b0\u589e\u6216\u66f4\u65b0\uff08\u4e0d\u7acb\u5373\u63d0\u4ea4\uff09",id:"981-\u65b0\u589e\u6216\u66f4\u65b0\u4e0d\u7acb\u5373\u63d0\u4ea4",level:2},{value:"9.8.2 \u65b0\u589e\u6216\u66f4\u65b0\uff08\u7acb\u5373\u63d0\u4ea4\uff09",id:"982-\u65b0\u589e\u6216\u66f4\u65b0\u7acb\u5373\u63d0\u4ea4",level:2},{value:"9.8.3 \u65b0\u589e\u6216\u66f4\u65b0\u90e8\u5206\u5217\uff08\u4e0d\u7acb\u5373\u63d0\u4ea4\uff09",id:"983-\u65b0\u589e\u6216\u66f4\u65b0\u90e8\u5206\u5217\u4e0d\u7acb\u5373\u63d0\u4ea4",level:2},{value:"9.8.4 \u65b0\u589e\u6216\u66f4\u65b0\u90e8\u5206\u5217\uff08\u7acb\u5373\u63d0\u4ea4\uff09",id:"984-\u65b0\u589e\u6216\u66f4\u65b0\u90e8\u5206\u5217\u7acb\u5373\u63d0\u4ea4",level:2},{value:"9.8.5 \u65b0\u589e\u6216\u66f4\u65b0\u6392\u9664\u7279\u5b9a\u5217\uff08\u4e0d\u7acb\u5373\u63d0\u4ea4\uff09",id:"985-\u65b0\u589e\u6216\u66f4\u65b0\u6392\u9664\u7279\u5b9a\u5217\u4e0d\u7acb\u5373\u63d0\u4ea4",level:2},{value:"9.8.6 \u65b0\u589e\u6216\u66f4\u65b0\u6392\u9664\u7279\u5b9a\u5217\uff08\u7acb\u5373\u63d0\u4ea4\uff09",id:"986-\u65b0\u589e\u6216\u66f4\u65b0\u6392\u9664\u7279\u5b9a\u5217\u7acb\u5373\u63d0\u4ea4",level:2},{value:"9.8.7 \u53cd\u9988\u4e0e\u5efa\u8bae",id:"987-\u53cd\u9988\u4e0e\u5efa\u8bae",level:2}];function i(e){const r={a:"a",admonition:"admonition",code:"code",h2:"h2",p:"p",pre:"pre",...(0,s.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r.admonition,{title:"\u529f\u80fd\u79fb\u9664\u58f0\u660e",type:"warning",children:(0,t.jsxs)(r.p,{children:["\u4ee5\u4e0b\u5185\u5bb9\u5728 ",(0,t.jsx)(r.code,{children:"Furion 2.5.1 +"})," \u7248\u672c\u4e2d\u5df2\u79fb\u9664\u3002\u6b64\u64cd\u4f5c\u8ba9\u5f88\u591a\u4e0d\u4e86\u89e3 ",(0,t.jsx)(r.code,{children:"EFCore"})," \u7684\u5f00\u53d1\u8005\u4ea7\u751f\u4e86\u5f88\u5927\u7684\u8bef\u89e3\uff0c\u4e0d\u77e5\u4f55\u65f6\u65b0\u589e\u6216\u4f55\u65f6\u66f4\u65b0\uff0c\u6545\u79fb\u9664\u6b64\u529f\u80fd\u3002"]})}),"\n",(0,t.jsx)(r.h2,{id:"981-\u65b0\u589e\u6216\u66f4\u65b0\u4e0d\u7acb\u5373\u63d0\u4ea4",children:"9.8.1 \u65b0\u589e\u6216\u66f4\u65b0\uff08\u4e0d\u7acb\u5373\u63d0\u4ea4\uff09"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nrepository.InsertOrUpdate(user);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nuser.InsertOrUpdate();\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nawait repository.InsertOrUpdateAsync(user);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nawait user.InsertOrUpdateAsync();\n"})}),"\n",(0,t.jsx)(r.h2,{id:"982-\u65b0\u589e\u6216\u66f4\u65b0\u7acb\u5373\u63d0\u4ea4",children:"9.8.2 \u65b0\u589e\u6216\u66f4\u65b0\uff08\u7acb\u5373\u63d0\u4ea4\uff09"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nrepository.InsertOrUpdateNow(user);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nuser.InsertOrUpdateNow();\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nawait repository.InsertOrUpdateNowAsync(user);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nawait user.InsertOrUpdateNowAsync();\n"})}),"\n",(0,t.jsx)(r.h2,{id:"983-\u65b0\u589e\u6216\u66f4\u65b0\u90e8\u5206\u5217\u4e0d\u7acb\u5373\u63d0\u4ea4",children:"9.8.3 \u65b0\u589e\u6216\u66f4\u65b0\u90e8\u5206\u5217\uff08\u4e0d\u7acb\u5373\u63d0\u4ea4\uff09"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:'// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nrepository.InsertOrUpdateInclude(user, u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nrepository.InsertOrUpdateInclude(user, "Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e09\r\nrepository.InsertOrUpdateInclude(user, new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u56db\r\nrepository.InsertOrUpdateInclude(user, new[] {"Age", "Name"});\r\n\r\n// \u793a\u4f8b\u4e94\r\nuser.InsertOrUpdateInclude(u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u516d\r\nuser.InsertOrUpdateInclude("Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e03\r\nuser.InsertOrUpdateInclude(new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u516b\r\nuser.InsertOrUpdateInclude(new[] {"Age", "Name"});\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nawait repository.InsertOrUpdateIncludeAsync(user, u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nawait repository.InsertOrUpdateIncludeAsync(user, "Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e09\r\nawait repository.InsertOrUpdateIncludeAsync(user, new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u56db\r\nawait repository.InsertOrUpdateIncludeAsync(user, new[] {"Age", "Name"});\r\n\r\n// \u793a\u4f8b\u4e94\r\nawait user.InsertOrUpdateIncludeAsync(u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u516d\r\nawait user.InsertOrUpdateIncludeAsync("Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e03\r\nawait user.InsertOrUpdateIncludeAsync(new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u516b\r\nawait user.InsertOrUpdateIncludeAsync(new[] {"Age", "Name"});\n'})}),"\n",(0,t.jsx)(r.h2,{id:"984-\u65b0\u589e\u6216\u66f4\u65b0\u90e8\u5206\u5217\u7acb\u5373\u63d0\u4ea4",children:"9.8.4 \u65b0\u589e\u6216\u66f4\u65b0\u90e8\u5206\u5217\uff08\u7acb\u5373\u63d0\u4ea4\uff09"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:'// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nrepository.InsertOrUpdateIncludeNow(user, u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nrepository.InsertOrUpdateIncludeNow(user, "Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e09\r\nrepository.InsertOrUpdateIncludeNow(user, new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u56db\r\nrepository.InsertOrUpdateIncludeNow(user, new[] {"Age", "Name"});\r\n\r\n// \u793a\u4f8b\u4e94\r\nuser.InsertOrUpdateIncludeNow(u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u516d\r\nuser.InsertOrUpdateIncludeNow("Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e03\r\nuser.InsertOrUpdateIncludeNow(new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u516b\r\nuser.InsertOrUpdateIncludeNow(new[] {"Age", "Name"});\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nawait repository.InsertOrUpdateIncludeNowAsync(user, u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nawait repository.InsertOrUpdateIncludeNowAsync(user, "Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e09\r\nawait repository.InsertOrUpdateIncludeNowAsync(user, new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u56db\r\nawait repository.InsertOrUpdateIncludeNowAsync(user, new[] {"Age", "Name"});\r\n\r\n// \u793a\u4f8b\u4e94\r\nawait user.InsertOrUpdateIncludeNowAsync(u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u516d\r\nawait user.InsertOrUpdateIncludeNowAsync("Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e03\r\nawait user.InsertOrUpdateIncludeNowAsync(new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u516b\r\nawait user.InsertOrUpdateIncludeNowAsync(new[] {"Age", "Name"});\n'})}),"\n",(0,t.jsx)(r.h2,{id:"985-\u65b0\u589e\u6216\u66f4\u65b0\u6392\u9664\u7279\u5b9a\u5217\u4e0d\u7acb\u5373\u63d0\u4ea4",children:"9.8.5 \u65b0\u589e\u6216\u66f4\u65b0\u6392\u9664\u7279\u5b9a\u5217\uff08\u4e0d\u7acb\u5373\u63d0\u4ea4\uff09"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:'// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nrepository.InsertOrUpdateExclude(user, u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nrepository.InsertOrUpdateExclude(user, "Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e09\r\nrepository.InsertOrUpdateExclude(user, new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u56db\r\nrepository.InsertOrUpdateExclude(user, new[] {"Age", "Name"});\r\n\r\n// \u793a\u4f8b\u4e94\r\nuser.InsertOrUpdateExclude(u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u516d\r\nuser.InsertOrUpdateExclude("Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e03\r\nuser.InsertOrUpdateExclude(new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u516b\r\nuser.InsertOrUpdateExclude(new[] {"Age", "Name"});\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nawait repository.InsertOrUpdateExcludeAsync(user, u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nawait repository.InsertOrUpdateExcludeAsync(user, "Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e09\r\nawait repository.InsertOrUpdateExcludeAsync(user, new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u56db\r\nawait repository.InsertOrUpdateExcludeAsync(user, new[] {"Age", "Name"});\r\n\r\n// \u793a\u4f8b\u4e94\r\nawait user.InsertOrUpdateExcludeAsync(u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u516d\r\nawait user.InsertOrUpdateExcludeAsync("Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e03\r\nawait user.InsertOrUpdateExcludeAsync(new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u516b\r\nawait user.InsertOrUpdateExcludeAsync(new[] {"Age", "Name"});\n'})}),"\n",(0,t.jsx)(r.h2,{id:"986-\u65b0\u589e\u6216\u66f4\u65b0\u6392\u9664\u7279\u5b9a\u5217\u7acb\u5373\u63d0\u4ea4",children:"9.8.6 \u65b0\u589e\u6216\u66f4\u65b0\u6392\u9664\u7279\u5b9a\u5217\uff08\u7acb\u5373\u63d0\u4ea4\uff09"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:'// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nrepository.InsertOrUpdateExcludeNow(user, u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nrepository.InsertOrUpdateExcludeNow(user, "Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e09\r\nrepository.InsertOrUpdateExcludeNow(user, new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u56db\r\nrepository.InsertOrUpdateExcludeNow(user, new[] {"Age", "Name"});\r\n\r\n// \u793a\u4f8b\u4e94\r\nuser.InsertOrUpdateExcludeNow(u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u516d\r\nuser.InsertOrUpdateExcludeNow("Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e03\r\nuser.InsertOrUpdateExcludeNow(new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u516b\r\nuser.InsertOrUpdateExcludeNow(new[] {"Age", "Name"});\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nawait repository.InsertOrUpdateExcludeNowAsync(user, u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nawait repository.InsertOrUpdateExcludeNowAsync(user, "Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e09\r\nawait repository.InsertOrUpdateExcludeNowAsync(user, new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u56db\r\nawait repository.InsertOrUpdateExcludeNowAsync(user, new[] {"Age", "Name"});\r\n\r\n// \u793a\u4f8b\u4e94\r\nawait user.InsertOrUpdateExcludeNowAsync(u=>u.Name, u=>u.Age);\r\n\r\n// \u793a\u4f8b\u516d\r\nawait user.InsertOrUpdateExcludeNowAsync("Age", "Name");\r\n\r\n// \u793a\u4f8b\u4e03\r\nawait user.InsertOrUpdateExcludeNowAsync(new[] { u=>u.Name, u=>u.Age});\r\n\r\n// \u793a\u4f8b\u516b\r\nawait user.InsertOrUpdateExcludeNowAsync(new[] {"Age", "Name"});\n'})}),"\n",(0,t.jsx)(r.h2,{id:"987-\u53cd\u9988\u4e0e\u5efa\u8bae",children:"9.8.7 \u53cd\u9988\u4e0e\u5efa\u8bae"}),"\n",(0,t.jsx)(r.admonition,{title:"\u4e0e\u6211\u4eec\u4ea4\u6d41",type:"note",children:(0,t.jsxs)(r.p,{children:["\u7ed9 Furion \u63d0 ",(0,t.jsx)(r.a,{href:"https://gitee.com/dotnetchina/Furion/issues/new?issue",children:"Issue"}),"\u3002"]})})]})}function l(e={}){const{wrapper:r}={...(0,s.a)(),...e.components};return r?(0,t.jsx)(r,{...e,children:(0,t.jsx)(i,{...e})}):i(e)}},1151:(e,r,n)=>{n.d(r,{Z:()=>d,a:()=>a});var t=n(7294);const s={},u=t.createContext(s);function a(e){const r=t.useContext(u);return t.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function d(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),t.createElement(u.Provider,{value:r},e.children)}}}]);