"use strict";(self.webpackChunkfurion=self.webpackChunkfurion||[]).push([[6696],{5622:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>d,contentTitle:()=>o,default:()=>h,frontMatter:()=>l,metadata:()=>u,toc:()=>c});var s=n(5893),t=n(1151),i=(n(4996),n(4866)),a=n(5162);const l={id:"dbcontext-hight-query",title:"9.12 \u9ad8\u7ea7\u67e5\u8be2\u64cd\u4f5c",sidebar_label:"9.12 \u9ad8\u7ea7\u67e5\u8be2\u64cd\u4f5c"},o=void 0,u={id:"dbcontext-hight-query",title:"9.12 \u9ad8\u7ea7\u67e5\u8be2\u64cd\u4f5c",description:"9.12.1 \u5173\u8054\u6570\u636e\u6a21\u578b",source:"@site/docs/dbcontext-high-query.mdx",sourceDirName:".",slug:"/dbcontext-hight-query",permalink:"/docs/dbcontext-hight-query",draft:!1,unlisted:!1,editUrl:"https://gitee.com/dotnetchina/Furion/tree/v4/handbook/docs/dbcontext-high-query.mdx",tags:[],version:"current",lastUpdatedBy:"MonkSoul",lastUpdatedAt:1682389320,formattedLastUpdatedAt:"Apr 25, 2023",frontMatter:{id:"dbcontext-hight-query",title:"9.12 \u9ad8\u7ea7\u67e5\u8be2\u64cd\u4f5c",sidebar_label:"9.12 \u9ad8\u7ea7\u67e5\u8be2\u64cd\u4f5c"},sidebar:"docs",previous:{title:"9.11 \u67e5\u8be2\u64cd\u4f5c",permalink:"/docs/dbcontext-query"},next:{title:"9.13 \u89c6\u56fe\u64cd\u4f5c",permalink:"/docs/dbcontext-view"}},d={},c=[{value:"9.12.1 \u5173\u8054\u6570\u636e\u6a21\u578b",id:"9121-\u5173\u8054\u6570\u636e\u6a21\u578b",level:2},{value:"9.12.2 \u4e00\u5bf9\u4e00\u67e5\u8be2",id:"9122-\u4e00\u5bf9\u4e00\u67e5\u8be2",level:2},{value:"9.12.3 \u4e00\u5bf9\u591a\u67e5\u8be2",id:"9123-\u4e00\u5bf9\u591a\u67e5\u8be2",level:2},{value:"9.12.4 \u591a\u5bf9\u591a\u67e5\u8be2",id:"9124-\u591a\u5bf9\u591a\u67e5\u8be2",level:2},{value:"9.12.5 \u8054\u8868\u67e5\u8be2",id:"9125-\u8054\u8868\u67e5\u8be2",level:2},{value:"9.12.5.1 \u5185\u8fde\u63a5 Inner Join",id:"91251-\u5185\u8fde\u63a5-inner-join",level:3},{value:"9.12.5.2 \u5de6\u8fde\u63a5 Left Join",id:"91252-\u5de6\u8fde\u63a5-left-join",level:3},{value:"9.12.5.3 \u53f3\u8fde\u63a5 Right Join",id:"91253-\u53f3\u8fde\u63a5-right-join",level:3},{value:"9.12.6 \u5206\u7ec4\u67e5\u8be2",id:"9126-\u5206\u7ec4\u67e5\u8be2",level:2},{value:"9.12.7 \u5408\u5e76\u7ed3\u679c\u96c6",id:"9127-\u5408\u5e76\u7ed3\u679c\u96c6",level:2},{value:"9.12.8 \u67e5\u8be2\u6392\u5e8f",id:"9128-\u67e5\u8be2\u6392\u5e8f",level:2},{value:"9.12.8.1 \u6b63\u5e8f",id:"91281-\u6b63\u5e8f",level:3},{value:"9.12.8.2 \u5012\u5e8f",id:"91282-\u5012\u5e8f",level:3},{value:"9.12.8.3 \u6df7\u5408\u5012\u5e8f",id:"91283-\u6df7\u5408\u5012\u5e8f",level:3},{value:"9.12.9 \u9012\u5f52\u67e5\u8be2",id:"9129-\u9012\u5f52\u67e5\u8be2",level:2},{value:"9.12.10 \u52a8\u6001 Sql \u67e5\u8be2",id:"91210-\u52a8\u6001-sql-\u67e5\u8be2",level:2},{value:"9.12.10.1 \u52a8\u6001 Sql",id:"912101-\u52a8\u6001-sql",level:3},{value:"9.12.10.2 \u52a8\u6001 Lambda",id:"912102-\u52a8\u6001-lambda",level:3},{value:"9.12.11 \u65f6\u6001\u67e5\u8be2",id:"91211-\u65f6\u6001\u67e5\u8be2",level:2},{value:"9.12.12 \u6027\u80fd\u4f18\u5316",id:"91212-\u6027\u80fd\u4f18\u5316",level:2},{value:"9.12.13 \u5206\u8868\u67e5\u8be2\u5c0f\u4f8b\u5b50",id:"91213-\u5206\u8868\u67e5\u8be2\u5c0f\u4f8b\u5b50",level:2},{value:"9.12.14 \u53cd\u9988\u4e0e\u5efa\u8bae",id:"91214-\u53cd\u9988\u4e0e\u5efa\u8bae",level:2}];function m(e){const r={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,t.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.h2,{id:"9121-\u5173\u8054\u6570\u636e\u6a21\u578b",children:"9.12.1 \u5173\u8054\u6570\u636e\u6a21\u578b"}),"\n",(0,s.jsxs)(i.Z,{defaultValue:"person",values:[{label:"Person",value:"person"},{label:"PersonDetail",value:"person-detail"},{label:"Children",value:"children"},{label:"Post",value:"post"}],children:[(0,s.jsx)(a.Z,{value:"person",children:(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {38,43,48}",children:"using Furion.DatabaseAccessor;\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.ComponentModel.DataAnnotations;\r\n\r\nnamespace Furion.Core\r\n{\r\n public class Person : Entity\r\n {\r\n /// \r\n /// \u6784\u9020\u51fd\u6570\r\n /// \r\n public Person()\r\n {\r\n CreatedTime = DateTime.Now;\r\n }\r\n\r\n /// \r\n /// \u59d3\u540d\r\n /// \r\n [MaxLength(32)]\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 /// \r\n /// \u4ece\u8868\r\n /// \r\n public PersonDetail PersonDetail { get; set; }\r\n\r\n /// \r\n /// \u4e00\u5bf9\u591a\r\n /// \r\n public ICollection Childrens { get; set; }\r\n\r\n /// \r\n /// \u591a\u5bf9\u591a\r\n /// \r\n public ICollection Posts { get; set; }\r\n }\r\n}\n"})})}),(0,s.jsx)(a.Z,{value:"person-detail",children:(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {25}",children:"using Furion.DatabaseAccessor;\r\n\r\nnamespace Furion.Core\r\n{\r\n public class PersonDetail : EntityBase\r\n {\r\n /// \r\n /// \u7535\u8bdd\u53f7\u7801\r\n /// \r\n public string PhoneNumber { get; set; }\r\n\r\n /// \r\n /// QQ \u53f7\u7801\r\n /// \r\n public string QQ { get; set; }\r\n\r\n /// \r\n /// \u5916\u952e\r\n /// \r\n public int PersonId { get; set; }\r\n\r\n /// \r\n /// \u4e3b\u8868\r\n /// \r\n public Person Person { get; set; }\r\n }\r\n}\n"})})}),(0,s.jsx)(a.Z,{value:"children",children:(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {35}",children:"using Furion.DatabaseAccessor;\r\nusing System;\r\n\r\nnamespace Furion.Core\r\n{\r\n public class Children : Entity\r\n {\r\n /// \r\n /// \u6784\u9020\u51fd\u6570\r\n /// \r\n public Children()\r\n {\r\n CreatedTime = DateTime.Now;\r\n\r\n }\r\n\r\n /// \r\n /// \u540d\u79f0\r\n /// \r\n public string Name { get; set; }\r\n\r\n /// \r\n /// \u6027\u522b\r\n /// \r\n public Gender Gender { get; set; }\r\n\r\n /// \r\n /// \u5916\u952e\r\n /// \r\n public int PersonId { get; set; }\r\n\r\n /// \r\n /// \u4e3b\u8868\r\n /// \r\n public Person Person { get; set; }\r\n }\r\n}\n"})})}),(0,s.jsx)(a.Z,{value:"post",children:(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {26}",children:"using Furion.DatabaseAccessor;\r\nusing System;\r\nusing System.Collections.Generic;\r\n\r\nnamespace Furion.Core\r\n{\r\n public class Post : Entity\r\n {\r\n /// \r\n /// \u6784\u9020\u51fd\u6570\r\n /// \r\n public Post()\r\n {\r\n CreatedTime = DateTime.Now;\r\n\r\n }\r\n\r\n /// \r\n /// \u540d\u79f0\r\n /// \r\n public string Name { get; set; }\r\n\r\n /// \r\n /// Person \u96c6\u5408\r\n /// \r\n public ICollection Persons { get; set; }\r\n }\r\n}\n"})})})]}),"\n",(0,s.jsx)(r.h2,{id:"9122-\u4e00\u5bf9\u4e00\u67e5\u8be2",children:"9.12.2 \u4e00\u5bf9\u4e00\u67e5\u8be2"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"// \u793a\u4f8b\u4e00\r\nvar person = repository.Include(u => u.Detail);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar person = repository.Include(u => u.Detail)\r\n .Include(u => u.Post);\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar person = repository.Include(u => u.Detail)\r\n .ThenInclude(d => d.Review)\r\n .Include(u => u.Post);\r\n\r\n// \u793a\u4f8b\u56db\r\nvar person = repository.Include(u => u.Detail.Where(d => d.Id > 10).OrderBy(d => d.Name))\r\n .ThenInclude(d => d.Review)\r\n .Include(u => u.Post);\r\n\r\n// \u793a\u4f8b\u4e94\r\nvar person = repository.Include(!string.IsNullOrEmpty(keyword), u => u.Detail);\r\n\r\n// \u793a\u4f8b\u516d\r\nvar person = repository.Include(!string.IsNullOrEmpty(keyword), u => u.Detail)\r\n .Include(age > 18, u => u.Detail.Where(d => d.Id > 10).OrderBy(d => d.Name))\r\n .ThenInclude(d => d.Review)\r\n .Include(u => u.Post);\n"})}),"\n",(0,s.jsx)(r.h2,{id:"9123-\u4e00\u5bf9\u591a\u67e5\u8be2",children:"9.12.3 \u4e00\u5bf9\u591a\u67e5\u8be2"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"// \u793a\u4f8b\u4e00\r\nvar person = repository.Include(u => u.Childrens);\r\n\r\n// \u53c2\u8003 \u4e00\u5bf9\u4e00 \u4f8b\u5b50\n"})}),"\n",(0,s.jsx)(r.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"important",children:(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"\u4e00\u5bf9\u4e00"})," \u548c ",(0,s.jsx)(r.code,{children:"\u4e00\u5bf9\u591a"})," \u67e5\u8be2\u65b9\u6cd5\u4e00\u6837\uff0c\u552f\u4e00\u7684\u533a\u522b\u662f\uff1a",(0,s.jsx)(r.code,{children:"\u4e00\u5bf9\u591a"})," \u91c7\u7528 ",(0,s.jsx)(r.code,{children:"ICollection"})," \u5b9a\u4e49\u5c5e\u6027\u3002"]})}),"\n",(0,s.jsx)(r.h2,{id:"9124-\u591a\u5bf9\u591a\u67e5\u8be2",children:"9.12.4 \u591a\u5bf9\u591a\u67e5\u8be2"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"// \u793a\u4f8b\u4e00\r\nvar person = repository.Include(u => u.Posts);\r\n\r\n// \u53c2\u8003 \u4e00\u5bf9\u4e00 \u4f8b\u5b50\n"})}),"\n",(0,s.jsx)(r.admonition,{title:"\u7279\u522b\u8bf4\u660e",type:"important",children:(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"\u4e00\u5bf9\u4e00"})," \u548c ",(0,s.jsx)(r.code,{children:"\u591a\u5bf9\u591a"})," \u67e5\u8be2\u65b9\u6cd5\u4e00\u6837\uff0c\u552f\u4e00\u7684\u533a\u522b\u662f\uff1a",(0,s.jsx)(r.code,{children:"\u591a\u5bf9\u591a"})," \u91c7\u7528 ",(0,s.jsx)(r.code,{children:"ICollection"})," \u5b9a\u4e49\u5c5e\u6027\u3002"]})}),"\n",(0,s.jsx)(r.h2,{id:"9125-\u8054\u8868\u67e5\u8be2",children:"9.12.5 \u8054\u8868\u67e5\u8be2"}),"\n",(0,s.jsxs)(r.h3,{id:"91251-\u5185\u8fde\u63a5-inner-join",children:["9.12.5.1 \u5185\u8fde\u63a5 ",(0,s.jsx)(r.code,{children:"Inner Join"})]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"var query = from p in _personRepository.AsQueryable()\r\n join d in _personDetailRepository.AsQueryable() on p.Id equals d.PersonId\r\n select new PersonDto\r\n {\r\n PhoneNumber = p.PersonDetail.PhoneNumber,\r\n Address = p.Address,\r\n Age = p.Age,\r\n Name = p.Name,\r\n Id = p.Id,\r\n QQ = p.PersonDetail.QQ\r\n };\n"})}),"\n",(0,s.jsxs)(r.h3,{id:"91252-\u5de6\u8fde\u63a5-left-join",children:["9.12.5.2 \u5de6\u8fde\u63a5 ",(0,s.jsx)(r.code,{children:"Left Join"})]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {2,3}",children:"var query = from p in _personRepository.AsQueryable()\r\n join d in _personDetailRepository.AsQueryable() on p.Id equals d.PersonId into results\r\n from d in results.DefaultIfEmpty()\r\n select new PersonDto\r\n {\r\n PhoneNumber = p.PersonDetail.PhoneNumber,\r\n Address = p.Address,\r\n Age = p.Age,\r\n Name = p.Name,\r\n Id = p.Id,\r\n QQ = p.PersonDetail.QQ\r\n };\n"})}),"\n",(0,s.jsx)(r.admonition,{title:"\u5c0f\u63d0\u793a",type:"note",children:(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.strong,{children:(0,s.jsx)(r.code,{children:"Left Join"})})," \u548c ",(0,s.jsx)(r.strong,{children:(0,s.jsx)(r.code,{children:"Inner Join"})})," \u4e0d\u540c\u7684\u662f\uff0c",(0,s.jsx)(r.strong,{children:(0,s.jsx)(r.code,{children:"Left Join"})})," \u4f1a\u5148\u5c06\u7ed3\u679c ",(0,s.jsx)(r.strong,{children:(0,s.jsx)(r.code,{children:"into"})})," \u5230\u65b0\u7684\u7ed3\u679c\u96c6\u7136\u540e\u518d\u67e5\u8be2\uff0c\u5e76\u8c03\u7528 ",(0,s.jsx)(r.strong,{children:(0,s.jsx)(r.code,{children:"DefaultIfEmpty()"})})," \u65b9\u6cd5\u3002"]})}),"\n",(0,s.jsxs)(r.h3,{id:"91253-\u53f3\u8fde\u63a5-right-join",children:["9.12.5.3 \u53f3\u8fde\u63a5 ",(0,s.jsx)(r.code,{children:"Right Join"})]}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"Right Join"})," \u53ea\u9700\u8981\u5c06 ",(0,s.jsx)(r.code,{children:"Left Join"})," \u4e3b\u4ece\u8868\u4f4d\u7f6e\u66f4\u6362\u5373\u53ef\u3002"]}),"\n",(0,s.jsx)(r.h2,{id:"9126-\u5206\u7ec4\u67e5\u8be2",children:"9.12.6 \u5206\u7ec4\u67e5\u8be2"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"// \u793a\u4f8b\u4e00\r\nvar query = repository.AsQueryable().GroupBy(x => new { x.Column1, x.Column2 });\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar query = from student in repository.AsQueryable()\r\n group student by repository2.AsQueryable() into dateGroup\r\n select new ResultData()\r\n {\r\n Key = dateGroup.Key,\r\n Value = dateGroup.Count()\r\n };\r\n\r\n// \u793a\u4f8b\u4e09\r\nvar query = from a in repository.AsQueryable()\r\n join b in repository2.AsQueryable() on a.Id equals b.Aid\r\n join c in repository3.AsQueryable() on c.id equals b.Bid\r\n group a by new { a.Age, b.Sex } into g\r\n select new {\r\n Peo = g.Key,\r\n Count = g.Count()\r\n };\n"})}),"\n",(0,s.jsx)(r.h2,{id:"9127-\u5408\u5e76\u7ed3\u679c\u96c6",children:"9.12.7 \u5408\u5e76\u7ed3\u679c\u96c6"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"var query = repository.AsQueryable(u => u.Id > 10)\r\n .Union(\r\n repository2.AsQueryable(u => u.Id <= 10)\r\n );\n"})}),"\n",(0,s.jsx)(r.h2,{id:"9128-\u67e5\u8be2\u6392\u5e8f",children:"9.12.8 \u67e5\u8be2\u6392\u5e8f"}),"\n",(0,s.jsx)(r.h3,{id:"91281-\u6b63\u5e8f",children:"9.12.8.1 \u6b63\u5e8f"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"// \u793a\u4f8b\u4e00\r\nvar query = repository.AsQueryable()\r\n .OrderBy(u => u.Id);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar query =repository.AsQueryable()\r\n .OrderBy(u => u.Id)\r\n .ThenBy(u => u.Name);\n"})}),"\n",(0,s.jsx)(r.h3,{id:"91282-\u5012\u5e8f",children:"9.12.8.2 \u5012\u5e8f"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"// \u793a\u4f8b\u4e00\r\nvar query = repository.AsQueryable()\r\n .OrderByDescending(u => u.Id);\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar query =repository.AsQueryable()\r\n .OrderByDescending(u => u.Id)\r\n .ThenByDescending(u => u.Name);\n"})}),"\n",(0,s.jsx)(r.h3,{id:"91283-\u6df7\u5408\u5012\u5e8f",children:"9.12.8.3 \u6df7\u5408\u5012\u5e8f"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"// \u793a\u4f8b\u4e00\r\nvar query = repository.AsQueryable()\r\n .OrderBy(u => u.Id)\r\n .OrderByDescending(u => u.Name)\r\n .ThenBy(u => u.Age);\n"})}),"\n",(0,s.jsx)(r.h2,{id:"9129-\u9012\u5f52\u67e5\u8be2",children:"9.12.9 \u9012\u5f52\u67e5\u8be2"}),"\n",(0,s.jsxs)(i.Z,{defaultValue:"city",values:[{label:"City",value:"city"},{label:"CityDto",value:"citydto"}],children:[(0,s.jsx)(a.Z,{value:"city",children:(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers {12,36,41,49-55}",children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\nusing Microsoft.EntityFrameworkCore.Metadata.Builders;\r\nusing System;\r\nusing System.Collections.Generic;\r\n\r\nnamespace Furion.Core\r\n{\r\n /// \r\n /// \u57ce\u5e02\r\n /// \r\n public class City : Entity, IEntityTypeBuilder, IEntitySeedData\r\n {\r\n /// \r\n /// \u6784\u9020\u51fd\u6570\r\n /// \r\n public City()\r\n {\r\n CreatedTime = DateTime.Now;\r\n\r\n }\r\n\r\n /// \r\n /// \u540d\u79f0\r\n /// \r\n public string Name { get; set; }\r\n\r\n /// \r\n /// \u4e0a\u7ea7Id\r\n /// \r\n public int? ParentId { get; set; }\r\n\r\n /// \r\n /// \u4e0a\u7ea7\r\n /// \r\n public virtual City Parent { get; set; }\r\n\r\n /// \r\n /// \u5b50\u96c6\r\n /// \r\n public virtual ICollection Childrens { get; set; }\r\n\r\n /// \r\n /// \u914d\u7f6e\u5b9e\u4f53\u5173\u7cfb\r\n /// \r\n /// \r\n /// \r\n /// \r\n public void Configure(EntityTypeBuilder entityBuilder, DbContext dbContext, Type dbContextLocator)\r\n {\r\n entityBuilder\r\n .HasMany(x => x.Childrens)\r\n .WithOne(x => x.Parent)\r\n .HasForeignKey(x => x.ParentId)\r\n .OnDelete(DeleteBehavior.ClientSetNull); // \u5fc5\u987b\u8bbe\u7f6e\u8fd9\u4e00\u884c\r\n }\r\n\r\n /// \r\n /// \u79cd\u5b50\u6570\u636e\r\n /// \r\n /// \r\n /// \r\n /// \r\n public IEnumerable HasData(DbContext dbContext, Type dbContextLocator)\r\n {\r\n return new List\r\n {\r\n new City { Id=1,CreatedTime =DateTime.Parse("2020-08-20 15:30:20"),IsDeleted=false,Name="\u4e2d\u56fd" },\r\n new City { Id=2,CreatedTime =DateTime.Parse("2020-08-20 15:30:20"),IsDeleted=false,Name="\u5e7f\u4e1c\u7701",ParentId=1 },\r\n new City { Id=3,CreatedTime =DateTime.Parse("2020-08-20 15:30:20"),IsDeleted=false,Name="\u4e2d\u5c71\u5e02",ParentId=2 },\r\n new City { Id=4,CreatedTime =DateTime.Parse("2020-08-20 15:30:20"),IsDeleted=false,Name="\u73e0\u6d77\u5e02",ParentId=2 },\r\n new City { Id=5,CreatedTime =DateTime.Parse("2020-08-20 15:30:20"),IsDeleted=false,Name="\u6d59\u6c5f\u7701",ParentId=1 },\r\n };\r\n }\r\n }\r\n}\n'})})}),(0,s.jsx)(a.Z,{value:"citydto",children:(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"using System.Collections.Generic;\r\n\r\nnamespace Furion.Application.Persons\r\n{\r\n public class CityDto\r\n {\r\n /// \r\n /// \u4e3b\u952e\r\n /// \r\n public int Id { get; set; }\r\n\r\n /// \r\n /// \u540d\u79f0\r\n /// \r\n public string Name { get; set; }\r\n\r\n /// \r\n /// \u5b50\u96c6\r\n /// \r\n public ICollection Childrens { get; set; }\r\n }\r\n}\n"})})})]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"var cities = await repository.AsQueryable()\r\n .Include(u => u.Childrens)\r\n .Where(u => u.Id == 1)\r\n .ToListAsync();\r\n\r\nvar dtos = cities.Adapt>();\n"})}),"\n",(0,s.jsxs)(r.h2,{id:"91210-\u52a8\u6001-sql-\u67e5\u8be2",children:["9.12.10 \u52a8\u6001 ",(0,s.jsx)(r.code,{children:"Sql"})," \u67e5\u8be2"]}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"Furion"})," \u9ed8\u8ba4\u4e0d\u652f\u6301 \u52a8\u6001 ",(0,s.jsx)(r.code,{children:"Sql"})," \u67e5\u8be2\u529f\u80fd\uff0c\u4e0d\u8fc7\u53ef\u4ee5\u901a\u8fc7\u7b2c\u4e09\u65b9\u5b9e\u73b0\uff1a"]}),"\n",(0,s.jsxs)(r.p,{children:["\u5728 ",(0,s.jsx)(r.code,{children:"Furion"})," \u9879\u76ee\u5c42\u5b89\u88c5 ",(0,s.jsx)(r.code,{children:"System.Linq.Dynamic.Core"})," \u5305 ",(0,s.jsx)(r.a,{href:"https://github.com/zzzprojects/System.Linq.Dynamic.Core",children:"https://github.com/zzzprojects/System.Linq.Dynamic.Core"})]}),"\n",(0,s.jsxs)(r.h3,{id:"912101-\u52a8\u6001-sql",children:["9.12.10.1 \u52a8\u6001 ",(0,s.jsx)(r.code,{children:"Sql"})]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:'// \u793a\u4f8b\u4e00\r\nvar query = repository.AsQueryable()\r\n .Where("City == @0 and Orders.Count >= @1", "China", 10)\r\n .OrderBy("CompanyName")\r\n .Select("new(CompanyName as Name, Phone)");\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar list = repository.AsQueryable()\r\n .Where("Name.Contains(@0)","Furion")\r\n .ToList();\r\n\r\n// \u793a\u4f8b\u4e09\uff0c\u652f\u6301 ? \u8bed\u6cd5\r\nvar customers = repository.AsQueryable()\r\n .Include(c => c.Location)\r\n .Where(c => c.Location?.Name == "test") // \u6ce8\u610f Location?.Name\r\n .ToList();\n'})}),"\n",(0,s.jsxs)(r.h3,{id:"912102-\u52a8\u6001-lambda",children:["9.12.10.2 \u52a8\u6001 ",(0,s.jsx)(r.code,{children:"Lambda"})]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:'// \u793a\u4f8b\u4e00\r\nvar x = Expression.Parameter(typeof(int), "x");\r\nvar y = Expression.Parameter(typeof(int), "y");\r\nvar e = DynamicExpressionParser\r\n .ParseLambda(new ParameterExpression[] { x, y }, null, "(x + y) * 2");\r\n\r\n// \u793a\u4f8b\u4e8c\r\nvar e = DynamicExpressionParser.ParseLambda(\r\n typeof(Customer), typeof(bool),\r\n "City = @0 and Orders.Count >= @1",\r\n "London", 10);\n'})}),"\n",(0,s.jsx)(r.h2,{id:"91211-\u65f6\u6001\u67e5\u8be2",children:"9.12.11 \u65f6\u6001\u67e5\u8be2"}),"\n",(0,s.jsx)(r.admonition,{title:"\u529f\u80fd\u79fb\u9664\u58f0\u660e",type:"warning",children:(0,s.jsxs)(r.p,{children:["\u4ee5\u4e0b\u5185\u5bb9\u5728 ",(0,s.jsx)(r.code,{children:"Furion 2.13 +"})," \u7248\u672c\u4e2d\u5df2\u79fb\u9664\u3002"]})}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"Furion"})," \u6846\u67b6\u8fd8\u63d0\u4f9b\u4e86\u65f6\u6001\u67e5\u8be2\u529f\u80fd\uff0c\u53ef\u4ee5\u67e5\u8be2\u7279\u5b9a\u65f6\u95f4\u7684\u6570\u636e\uff0c\u5982\uff1a"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:'var result = rep.Entities\r\n .AsTemporalOf(DateTime.UtcNow.AddDays(-1))\r\n .Include(i=> i.Company)\r\n .FirstOrDefault(i => i.Name == "Furion");\n'})}),"\n",(0,s.jsx)(r.p,{children:"\u53e6\u5916\u63d0\u4f9b\u4e86\u591a\u4e2a\u65f6\u6001\u67e5\u8be2\u65b9\u6cd5"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"AsTemporalAll()"}),"\n",(0,s.jsx)(r.li,{children:"AsTemporalAsOf(date)"}),"\n",(0,s.jsx)(r.li,{children:"AsTemporalFrom(startDate, endDate)"}),"\n",(0,s.jsx)(r.li,{children:"AsTemporalBetween(startDate, endDate)"}),"\n",(0,s.jsx)(r.li,{children:"AsTemporalContained(startDate, endDate)"}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"91212-\u6027\u80fd\u4f18\u5316",children:"9.12.12 \u6027\u80fd\u4f18\u5316"}),"\n",(0,s.jsxs)(r.p,{children:["\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c",(0,s.jsx)(r.code,{children:"EF Core"})," \u4f1a\u8ddf\u8e2a\u6240\u6709\u5b9e\u4f53\uff0c\u4e5f\u5c31\u662f\u4efb\u4f55\u6570\u636e\u6539\u53d8\u90fd\u4f1a\u5f15\u8d77\u6570\u636e\u68c0\u67e5\uff0c\u6240\u4ee5\u5982\u679c\u53ea\u505a\u67e5\u8be2\u64cd\u4f5c\uff0c\u5efa\u8bae\u5173\u95ed\u5b9e\u4f53\u8ddf\u8e2a\u529f\u80fd\u3002"]}),"\n",(0,s.jsxs)(r.p,{children:[(0,s.jsx)(r.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u9ad8\u6027\u80fd\u5b9e\u4f53\u96c6\u5408\uff1a"]}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"DetachedEntities"}),"\uff1a\u8131\u8f68/\u4e0d\u8ffd\u8e2a\u5b9e\u4f53"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"AsQueryable(false)"}),"\uff1a\u4e0d\u8ffd\u8e2a\u5b9e\u4f53"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"Entities.AsNoTracking()"}),"\uff1a\u624b\u52a8\u5173\u95ed\u5b9e\u4f53\u8ffd\u8e2a"]}),"\n"]}),"\n",(0,s.jsxs)(r.p,{children:["\u5728 ",(0,s.jsx)(r.code,{children:"EF Core"})," \u4e2d\uff0c\u590d\u6742\u67e5\u8be2\u603b\u662f\u4f1a\u751f\u6210\u4e00\u4e2a ",(0,s.jsx)(r.code,{children:"sql"}),"\uff0c\u4e5f\u5c31\u662f ",(0,s.jsx)(r.code,{children:"AsSingleQuery()"}),"\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u4e3a ",(0,s.jsx)(r.code,{children:"AsSplitQuery()"})," \u5207\u5272\u6210\u591a\u4e2a\u67e5\u8be2\u3002"]}),"\n",(0,s.jsx)(r.h2,{id:"91213-\u5206\u8868\u67e5\u8be2\u5c0f\u4f8b\u5b50",children:"9.12.13 \u5206\u8868\u67e5\u8be2\u5c0f\u4f8b\u5b50"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:'using Furion.DatabaseAccessor;\r\nusing Microsoft.EntityFrameworkCore;\r\nusing Microsoft.EntityFrameworkCore.Metadata.Builders;\r\nusing System;\r\nusing System.Collections.Generic;\r\n\r\nnamespace Furion.Core\r\n{\r\n public class Person : Entity, IEntityTypeBuilder\r\n {\r\n public string Name { get; set; }\r\n\r\n /// \r\n /// \u914d\u7f6e\u5b9e\u4f53\u5173\u7cfb\r\n /// \r\n /// \r\n /// \r\n /// \r\n public void Configure(EntityTypeBuilder entityBuilder, DbContext dbContext, Type dbContextLocator)\r\n {\r\n entityBuilder.ToSqlQuery(\r\n @"select * from dbo.person.2020-09-19\r\n union all\r\n select * from dbo.person.2020-09-20");\r\n }\r\n }\r\n}\n'})}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-cs",metastring:"showLineNumbers",children:"var posts = repository.Where(u => u.Id > 10).ToList();\n"})}),"\n",(0,s.jsx)(r.h2,{id:"91214-\u53cd\u9988\u4e0e\u5efa\u8bae",children:"9.12.14 \u53cd\u9988\u4e0e\u5efa\u8bae"}),"\n",(0,s.jsx)(r.admonition,{title:"\u4e0e\u6211\u4eec\u4ea4\u6d41",type:"note",children:(0,s.jsxs)(r.p,{children:["\u7ed9 Furion \u63d0 ",(0,s.jsx)(r.a,{href:"https://gitee.com/dotnetchina/Furion/issues/new?issue",children:"Issue"}),"\u3002"]})})]})}function h(e={}){const{wrapper:r}={...(0,t.a)(),...e.components};return r?(0,s.jsx)(r,{...e,children:(0,s.jsx)(m,{...e})}):m(e)}},5162:(e,r,n)=>{n.d(r,{Z:()=>a});n(7294);var s=n(4334);const t={tabItem:"tabItem_Ymn6"};var i=n(5893);function a(e){let{children:r,hidden:n,className:a}=e;return(0,i.jsx)("div",{role:"tabpanel",className:(0,s.Z)(t.tabItem,a),hidden:n,children:r})}},4866:(e,r,n)=>{n.d(r,{Z:()=>C});var s=n(7294),t=n(4334),i=n(2466),a=n(6550),l=n(469),o=n(1980),u=n(7392),d=n(12);function c(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:r}=e;return!!r&&"object"==typeof r&&"value"in r}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:r,children:n}=e;return(0,s.useMemo)((()=>{const e=r??function(e){return c(e).map((e=>{let{props:{value:r,label:n,attributes:s,default:t}}=e;return{value:r,label:n,attributes:s,default:t}}))}(n);return function(e){const r=(0,u.l)(e,((e,r)=>e.value===r.value));if(r.length>0)throw new Error(`Docusaurus error: Duplicate values "${r.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[r,n])}function h(e){let{value:r,tabValues:n}=e;return n.some((e=>e.value===r))}function p(e){let{queryString:r=!1,groupId:n}=e;const t=(0,a.k6)(),i=function(e){let{queryString:r=!1,groupId:n}=e;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:r,groupId:n});return[(0,o._X)(i),(0,s.useCallback)((e=>{if(!i)return;const r=new URLSearchParams(t.location.search);r.set(i,e),t.replace({...t.location,search:r.toString()})}),[i,t])]}function y(e){const{defaultValue:r,queryString:n=!1,groupId:t}=e,i=m(e),[a,o]=(0,s.useState)((()=>function(e){let{defaultValue:r,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(r){if(!h({value:r,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${r}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return r}const s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:r,tabValues:i}))),[u,c]=p({queryString:n,groupId:t}),[y,x]=function(e){let{groupId:r}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(r),[t,i]=(0,d.Nk)(n);return[t,(0,s.useCallback)((e=>{n&&i.set(e)}),[n,i])]}({groupId:t}),b=(()=>{const e=u??y;return h({value:e,tabValues:i})?e:null})();(0,l.Z)((()=>{b&&o(b)}),[b]);return{selectedValue:a,selectValue:(0,s.useCallback)((e=>{if(!h({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);o(e),c(e),x(e)}),[c,x,i]),tabValues:i}}var x=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=n(5893);function j(e){let{className:r,block:n,selectedValue:s,selectValue:a,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:u}=(0,i.o5)(),d=e=>{const r=e.currentTarget,n=o.indexOf(r),t=l[n].value;t!==s&&(u(r),a(t))},c=e=>{let r=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;r=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;r=o[n]??o[o.length-1];break}}r?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,t.Z)("tabs",{"tabs--block":n},r),children:l.map((e=>{let{value:r,label:n,attributes:i}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:s===r?0:-1,"aria-selected":s===r,ref:e=>o.push(e),onKeyDown:c,onClick:d,...i,className:(0,t.Z)("tabs__item",b.tabItem,i?.className,{"tabs__item--active":s===r}),children:n??r},r)}))})}function v(e){let{lazy:r,children:n,selectedValue:t}=e;const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(r){const e=i.find((e=>e.props.value===t));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:i.map(((e,r)=>(0,s.cloneElement)(e,{key:r,hidden:e.props.value!==t})))})}function f(e){const r=y(e);return(0,g.jsxs)("div",{className:(0,t.Z)("tabs-container",b.tabList),children:[(0,g.jsx)(j,{...e,...r}),(0,g.jsx)(v,{...e,...r})]})}function C(e){const r=(0,x.Z)();return(0,g.jsx)(f,{...e,children:c(e.children)},String(r))}},1151:(e,r,n)=>{n.d(r,{Z:()=>l,a:()=>a});var s=n(7294);const t={},i=s.createContext(t);function a(e){const r=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function l(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:a(e.components),s.createElement(i.Provider,{value:r},e.children)}}}]);