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
20 KiB
JavaScript
1 line
20 KiB
JavaScript
"use strict";(self.webpackChunkfurion=self.webpackChunkfurion||[]).push([[4821],{2679:(r,n,e)=>{e.r(n),e.d(n,{assets:()=>u,contentTitle:()=>a,default:()=>l,frontMatter:()=>t,metadata:()=>o,toc:()=>d});var s=e(5893),i=e(1151);const t={id:"dbcontext-query",title:"9.11 \u67e5\u8be2\u64cd\u4f5c",sidebar_label:"9.11 \u67e5\u8be2\u64cd\u4f5c"},a=void 0,o={id:"dbcontext-query",title:"9.11 \u67e5\u8be2\u64cd\u4f5c",description:"9.11.1 \u6839\u636e\u4e3b\u952e\u67e5\u8be2\u4e00\u6761",source:"@site/docs/dbcontext-query.mdx",sourceDirName:".",slug:"/dbcontext-query",permalink:"/docs/dbcontext-query",draft:!1,unlisted:!1,editUrl:"https://gitee.com/dotnetchina/Furion/tree/v4/handbook/docs/dbcontext-query.mdx",tags:[],version:"current",lastUpdatedBy:"MonkSoul",lastUpdatedAt:1682389320,formattedLastUpdatedAt:"Apr 25, 2023",frontMatter:{id:"dbcontext-query",title:"9.11 \u67e5\u8be2\u64cd\u4f5c",sidebar_label:"9.11 \u67e5\u8be2\u64cd\u4f5c"},sidebar:"docs",previous:{title:"9.10 \u6279\u91cf\u64cd\u4f5c",permalink:"/docs/dbcontext-batch"},next:{title:"9.12 \u9ad8\u7ea7\u67e5\u8be2\u64cd\u4f5c",permalink:"/docs/dbcontext-hight-query"}},u={},d=[{value:"9.11.1 \u6839\u636e\u4e3b\u952e\u67e5\u8be2\u4e00\u6761",id:"9111-\u6839\u636e\u4e3b\u952e\u67e5\u8be2\u4e00\u6761",level:2},{value:"9.11.2 \u6839\u636e\u6761\u4ef6\u67e5\u8be2\u4e00\u6761",id:"9112-\u6839\u636e\u6761\u4ef6\u67e5\u8be2\u4e00\u6761",level:2},{value:"9.11.3 \u67e5\u8be2\u6240\u6709\u6570\u636e",id:"9113-\u67e5\u8be2\u6240\u6709\u6570\u636e",level:2},{value:"9.11.4 \u6839\u636e\u6761\u4ef6\u67e5\u8be2\u6240\u6709\u6570\u636e",id:"9114-\u6839\u636e\u6761\u4ef6\u67e5\u8be2\u6240\u6709\u6570\u636e",level:2},{value:"9.11.5 \u5206\u9875\u67e5\u8be2",id:"9115-\u5206\u9875\u67e5\u8be2",level:2},{value:"9.11.6 \u5176\u4ed6\u67e5\u8be2",id:"9116-\u5176\u4ed6\u67e5\u8be2",level:2},{value:"9.11.6.1 \u67e5\u770b\u8bb0\u5f55\u662f\u5426\u5b58\u5728",id:"91161-\u67e5\u770b\u8bb0\u5f55\u662f\u5426\u5b58\u5728",level:3},{value:"9.11.6.2 \u67e5\u8be2\u8bb0\u5f55\u6570",id:"91162-\u67e5\u8be2\u8bb0\u5f55\u6570",level:3},{value:"9.11.6.3 \u67e5\u8be2\u6700\u5927\u503c",id:"91163-\u67e5\u8be2\u6700\u5927\u503c",level:3},{value:"9.11.6.4 \u67e5\u8be2\u6700\u5c0f\u503c",id:"91164-\u67e5\u8be2\u6700\u5c0f\u503c",level:3},{value:"9.11.6.5 \u6c42\u548c\u67e5\u8be2",id:"91165-\u6c42\u548c\u67e5\u8be2",level:3},{value:"9.11.6.6 \u6c42\u5e73\u5747\u503c\u67e5\u8be2",id:"91166-\u6c42\u5e73\u5747\u503c\u67e5\u8be2",level:3},{value:"9.11.6.7 \u65f6\u95f4\u67e5\u8be2",id:"91167-\u65f6\u95f4\u67e5\u8be2",level:3},{value:"9.11.6.8 \u6a21\u7cca\u67e5\u8be2",id:"91168-\u6a21\u7cca\u67e5\u8be2",level:3},{value:"9.11.6.9 <code>Case When</code>",id:"91169-case-when",level:3},{value:"9.11.7 \u53cd\u9988\u4e0e\u5efa\u8bae",id:"9117-\u53cd\u9988\u4e0e\u5efa\u8bae",level:2}];function c(r){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,i.a)(),...r.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.h2,{id:"9111-\u6839\u636e\u4e3b\u952e\u67e5\u8be2\u4e00\u6761",children:"9.11.1 \u6839\u636e\u4e3b\u952e\u67e5\u8be2\u4e00\u6761"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar person = repository.Find(1);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar person = repository.FindOrDefault(1);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar person = repository.Entities.Find(1);\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar person = await repository.FindAsync(1);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar person = await repository.FindOrDefaultAsync(1);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar person = await repository.Entities.FindAsync(1);\r\n\n"})}),"\n",(0,s.jsx)(n.admonition,{title:"\u5c0f\u63d0\u793a",type:"tip",children:(0,s.jsxs)(n.p,{children:["\u53ef\u4ee5\u652f\u6301\u591a\u4e2a\u952e\u67e5\u8be2\uff0c\u5982\u4e3b\u952e\u3001\u8054\u5408\u952e\u3002",(0,s.jsx)(n.code,{children:'repository.Find(1, "\u767e\u5c0f\u50e7")'}),";"]})}),"\n",(0,s.jsx)(n.h2,{id:"9112-\u6839\u636e\u6761\u4ef6\u67e5\u8be2\u4e00\u6761",children:"9.11.2 \u6839\u636e\u6761\u4ef6\u67e5\u8be2\u4e00\u6761"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar person = repository.Single(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar person = repository.SingleOrDefault(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar person = repository.First(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u56db\r\nvar person = repository.FirstOrDefault(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar person = repository.Last(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u516d\r\nvar person = repository.LastOrDefault(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u4e03\r\nvar person = repository.Entities.Single(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u516b\r\nvar person = repository.Entities.First(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u4e5d\r\nvar person = repository.Entities.FirstOrDefault(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u5341\r\nvar person = repository.Entities.Last(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u5341\u4e00\r\nvar person = repository.Entities.LastOrDefault(u => u.Name == "Furion");\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar person = await repository.SingleAsync(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar person = await repository.SingleOrDefaultAsync(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar person = await repository.FirstAsync(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u56db\r\nvar person = await repository.FirstOrDefaultAsync(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar person = await repository.LastAsync(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u516d\r\nvar person = await repository.LastOrDefaultAsync(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u4e03\r\nvar person = await repository.Entities.SingleAsync(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u516b\r\nvar person = await repository.Entities.FirstAsync(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u4e5d\r\nvar person = await repository.Entities.FirstOrDefaultAsync(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u5341\r\nvar person = await repository.Entities.LastAsync(u => u.Name == "Furion");\r\n\r\n// \u793a\u4f8b\u5341\u4e00\r\nvar person = await repository.Entities.LastOrDefaultAsync(u => u.Name == "Furion");\n'})}),"\n",(0,s.jsx)(n.h2,{id:"9113-\u67e5\u8be2\u6240\u6709\u6570\u636e",children:"9.11.3 \u67e5\u8be2\u6240\u6709\u6570\u636e"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar persons = repository.Entities;\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar persons = repository.DetachedEntities;\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar persons = repository.AsQueryable();\r\n\r\n// \u793a\u4f8b\u56db\r\nvar persons = repository.AsEnumerable();\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar persons = await repository.AsQueryable().ToListAsync();\n"})}),"\n",(0,s.jsx)(n.h2,{id:"9114-\u6839\u636e\u6761\u4ef6\u67e5\u8be2\u6240\u6709\u6570\u636e",children:"9.11.4 \u6839\u636e\u6761\u4ef6\u67e5\u8be2\u6240\u6709\u6570\u636e"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'// \u793a\u4f8b\u4e00\r\nvar persons = repository.Where(u => u.Id > 10);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar persons = repository.Where(u => u.Id > 10 && u.Name.Equals("Furion"));\r\n\r\n// \u793a\u4f8b\u4e09 (\u591a\u4e2a where \u91cc\u662f "\u5e76\u4e14"\uff0cId>10 and Name == "Furion")\r\nvar persons = repository.Where(u => u.Id > 10).Where(u => u.Name.Equals("Furion"));\r\n\r\n// \u793a\u4f8b\u56db (\u5224\u65ad name \u662f\u5426\u6709\u503c\uff0c\u5982\u679c name \u662f\u7a7a\u7684\u5219\u4e0d\u4f1a\u6267\u884c u => u.Id > 10 && u.Name.Equals("Furion")\uff0c\u5982\u679c name \u6709\u503c\u5c31\u4f1a\u6267\u884c u => u.Id > 10 && u.Name.Equals("Furion"))\r\nvar persons = repository.Where(!string.IsNullOrEmpty(name), u => u.Id > 10 && u.Name.Equals("Furion"));\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar persons = repository.Where(!string.IsNullOrEmpty(name), u => u.Id > 10)\r\n .Where(age > 18, u => u.Name.Contains("\u767e\u5c0f\u50e7"))\r\n .Where(u => u.Age > 18);\r\n\r\n// \u793a\u4f8b\u516d (\u5728\u4e00\u4e2a where \u91cc\u7528\u9017\u53f7\u5206\u9694\u662f "\u6216\u8005"\uff0cName=="Furion" or Name == "\u767e\u5c0f\u50e7" or Name == "MonkSoul")\r\nvar persons = repository.Where(u => u.Name == "Furion",\r\n u => u.Name == "\u767e\u5c0f\u50e7",\r\n u => u.Name == "MonkSoul");\r\n\r\n// \u793a\u4f8b\u4e03\r\nvar persons = repository.Where(u => u.Id > 10).Where(u => u.Name.Equals("Furion"))\r\n .Where(age > 18, u => u.Name.Contains("\u767e\u5c0f\u50e7"))\r\n .Where(u => u.Name == "Furion",\r\n u => u.Name == "\u767e\u5c0f\u50e7",\r\n u => u.Name == "MonkSoul");\r\n\r\n// \u793a\u4f8b\u516b\r\nvar persons = repository.Where((age > 18, u => u.Name == "Furion"),\r\n (!string.IsNullOrEmpty(name), u => u.Id > 10));\r\n\r\n// \u793a\u4f8b\u4e5d\r\nvar persons = repository.Where(u => u.Id > 10).Where(u => u.Name.Equals("Furion"))\r\n .Where(age > 18, u => u.Name.Contains("\u767e\u5c0f\u50e7"))\r\n .Where(u => u.Name == "Furion",\r\n u => u.Name == "\u767e\u5c0f\u50e7",\r\n u => u.Name == "MonkSoul")\r\n .Where((age > 18, u => u.Name == "Furion"),\r\n (!string.IsNullOrEmpty(name), u => u.Id > 10));\r\n\r\n// \u793a\u4f8b\u5341\r\nvar persons = repository.Entities.Where(u => u.Id > 10)\r\n .Where(age > 18, u => u.Name.Contains("\u767e\u5c0f\u50e7"));\r\n\r\n// \u793a\u4f8b\u5341\u4e00\r\nvar persons = repository.DetachedEntities.Where(u => u.Id > 20);\r\n\r\n// \u793a\u4f8b\u5341\u4e8c\r\nvar persons = repository.AsQueryable(u => u.Id > 20).Where(u => u.Name == "Furion");\n'})}),"\n",(0,s.jsx)(n.h2,{id:"9115-\u5206\u9875\u67e5\u8be2",children:"9.11.5 \u5206\u9875\u67e5\u8be2"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar persons = repository.Where(u => u.Id > 10).ToPagedList();\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar persons = repository.Where(u => u.Id > 10).ToPagedList(1, 10);\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar persons = await repository.Where(u => u.Id > 10).ToPagedListAsync();\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar persons = await repository.Where(u => u.Id > 10).ToPagedListAsync(1, 10);\n"})}),"\n",(0,s.jsx)(n.h2,{id:"9116-\u5176\u4ed6\u67e5\u8be2",children:"9.11.6 \u5176\u4ed6\u67e5\u8be2"}),"\n",(0,s.jsx)(n.h3,{id:"91161-\u67e5\u770b\u8bb0\u5f55\u662f\u5426\u5b58\u5728",children:"9.11.6.1 \u67e5\u770b\u8bb0\u5f55\u662f\u5426\u5b58\u5728"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar isExists = repository.Any();\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar isExists = repository.Any(u => u.Id > 10);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar isExists = repository.Entities.Any();\r\n\r\n// \u793a\u4f8b\u56db\r\nvar isExists = repository.DetachedEntities.Any(u => u.Id > 10);\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar isExists = repository.Where(u => u.Id > 10).Any();\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar isExists = await repository.AnyAsync();\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar isExists = await repository.AnyAsync(u => u.Id > 10);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar isExists = await repository.Entities.AnyAsync();\r\n\r\n// \u793a\u4f8b\u56db\r\nvar isExists = await repository.DetachedEntities.AnyAsync(u => u.Id > 10);\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar isExists = await repository.Where(u => u.Id > 10).AnyAsync();\n"})}),"\n",(0,s.jsx)(n.h3,{id:"91162-\u67e5\u8be2\u8bb0\u5f55\u6570",children:"9.11.6.2 \u67e5\u8be2\u8bb0\u5f55\u6570"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar count = repository.Count();\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar count = repository.Count(u => u.Id > 10);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar count = repository.Entities.Count(u => u.Id > 10);\r\n\r\n// \u793a\u4f8b\u56db\r\nvar count = repository.Entities.DetachedEntities.Count();\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar count = repository.Where(u => u.Id > 10).Count();\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar count = await repository.CountAsync();\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar count = await repository.CountAsync(u => u.Id > 10);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar count = await repository.Entities.CountAsync(u => u.Id > 10);\r\n\r\n// \u793a\u4f8b\u56db\r\nvar count = await repository.Entities.DetachedEntities.CountAsync();\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar count = await repository.Where(u => u.Id > 10).CountAsync();\n"})}),"\n",(0,s.jsx)(n.h3,{id:"91163-\u67e5\u8be2\u6700\u5927\u503c",children:"9.11.6.3 \u67e5\u8be2\u6700\u5927\u503c"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar entity = repository.Max();\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar value = repository.Max(u => u.Id);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar entity = repository.Entities.Max();\r\n\r\n// \u793a\u4f8b\u56db\r\nvar value = repository.Entities.DetachedEntities.Max(u => u.Age);\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar value = repository.Where(u => u.Id > 10).Max(u => u.Age);\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar entity = await repository.MaxAsync();\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar value = await repository.MaxAsync(u => u.Id);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar entity = await repository.Entities.MaxAsync();\r\n\r\n// \u793a\u4f8b\u56db\r\nvar value = await repository.Entities.DetachedEntities.MaxAsync(u => u.Age);\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar value = await repository.Where(u => u.Id > 10).MaxAsync(u => u.Age);\n"})}),"\n",(0,s.jsx)(n.h3,{id:"91164-\u67e5\u8be2\u6700\u5c0f\u503c",children:"9.11.6.4 \u67e5\u8be2\u6700\u5c0f\u503c"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar entity = repository.Min();\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar value = repository.Min(u => u.Id);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar entity = repository.Entities.Min();\r\n\r\n// \u793a\u4f8b\u56db\r\nvar value = repository.Entities.DetachedEntities.Min(u => u.Age);\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar value = repository.Where(u => u.Id > 10).Min(u => u.Age);\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar entity = await repository.MinAsync();\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar value = await repository.MinAsync(u => u.Id);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar entity = await repository.Entities.MinAsync();\r\n\r\n// \u793a\u4f8b\u56db\r\nvar value = await repository.Entities.DetachedEntities.MinAsync(u => u.Age);\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar value = await repository.Where(u => u.Id > 10).MinAsync(u => u.Age);\n"})}),"\n",(0,s.jsx)(n.h3,{id:"91165-\u6c42\u548c\u67e5\u8be2",children:"9.11.6.5 \u6c42\u548c\u67e5\u8be2"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar sum = repository.Entities.Sum(u => u.Cost);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar sum = repository.AsQueryable().Sum(u => u.Cost);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar sum = repository.DetachedEntities.Sum(u => u.Cost);\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar sum = await repository.Entities.SumAsync(u => u.Cost);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar sum = await repository.AsQueryable().SumAsync(u => u.Cost);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar sum = await repository.DetachedEntities.SumAsync(u => u.Cost);\n"})}),"\n",(0,s.jsx)(n.h3,{id:"91166-\u6c42\u5e73\u5747\u503c\u67e5\u8be2",children:"9.11.6.6 \u6c42\u5e73\u5747\u503c\u67e5\u8be2"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"// ==== \u540c\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar sum = repository.Entities.Average(u => u.Cost);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar sum = repository.AsQueryable().Average(u => u.Cost);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar sum = repository.DetachedEntities.Average(u => u.Cost);\r\n\r\n// ==== \u5f02\u6b65\u64cd\u4f5c ====\r\n\r\n// \u793a\u4f8b\u4e00\r\nvar sum = await repository.Entities.AverageAsync(u => u.Cost);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar sum = await repository.AsQueryable().AverageAsync(u => u.Cost);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar sum = await repository.DetachedEntities.AverageAsync(u => u.Cost);\n"})}),"\n",(0,s.jsx)(n.h3,{id:"91167-\u65f6\u95f4\u67e5\u8be2",children:"9.11.6.7 \u65f6\u95f4\u67e5\u8be2"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'var starDate = DateTime.Parse("2020-09-10");\r\nvar endDate = DateTime.Parse("2020-09-10");\r\nvar query = repository.Where(u => u.CreatedDt >= starDate && u.CreatedDt <= endDate);\n'})}),"\n",(0,s.jsx)(n.h3,{id:"91168-\u6a21\u7cca\u67e5\u8be2",children:"9.11.6.8 \u6a21\u7cca\u67e5\u8be2"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'// \u793a\u4f8b\u4e00\r\nrepository.Where(u => u.Name.StartsWith("Furion"));\r\n\r\n// \u793a\u4f8b\u4e8c\r\n_testRepository.Where(u => u.Name.EndsWith("Furion"));\r\n\r\n// \u793a\u4f8b\u4e09\r\n_testRepository.Where(u => u.Name.Contains("Furion"));\n'})}),"\n",(0,s.jsxs)(n.h3,{id:"91169-case-when",children:["9.11.6.9 ",(0,s.jsx)(n.code,{children:"Case When"})]}),"\n",(0,s.jsxs)(n.p,{children:["\u6570\u636e\u5e93\u4e2d\u7684 ",(0,s.jsx)(n.code,{children:"Case When"})," \u5b9e\u9645\u4e0a\u5bf9\u5e94\u7684\u662f\u6211\u4eec\u7a0b\u5e8f\u4e2d\u7684 ",(0,s.jsx)(n.code,{children:"\u4e09\u5143\u8868\u8fbe\u5f0f"})," \uff0c\u4e5f\u5c31\u662f\u4f7f\u7528 ",(0,s.jsx)(n.code,{children:"\u4e09\u5143\u8868\u8fbe\u5f0f"})," \u5373\u53ef\u81ea\u52a8\u751f\u6210 ",(0,s.jsx)(n.code,{children:"Case When"})," \u8bed\u53e5\u3002"]}),"\n",(0,s.jsx)(n.h2,{id:"9117-\u53cd\u9988\u4e0e\u5efa\u8bae",children:"9.11.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 l(r={}){const{wrapper:n}={...(0,i.a)(),...r.components};return n?(0,s.jsx)(n,{...r,children:(0,s.jsx)(c,{...r})}):c(r)}},1151:(r,n,e)=>{e.d(n,{Z:()=>o,a:()=>a});var s=e(7294);const i={},t=s.createContext(i);function a(r){const n=s.useContext(t);return s.useMemo((function(){return"function"==typeof r?r(n):{...n,...r}}),[n,r])}function o(r){let n;return n=r.disableParentContext?"function"==typeof r.components?r.components(i):r.components||i:a(r.components),s.createElement(t.Provider,{value:n},r.children)}}}]); |