├── .editorconfig
├── .gitattributes
├── .gitignore
├── .nuget
├── NuGet.Config
├── NuGet.exe
└── NuGet.targets
├── DapperDal.nuspec
├── DapperDal.sln
├── LICENSE
├── README.md
├── api
├── .gitignore
├── .manifest
└── index.md
├── buildPackage.cmd
├── docfx.json
├── src
└── DapperDal
│ ├── DalBaseOfTEntity..cs
│ ├── DalBaseOfTEntity.Count.cs
│ ├── DalBaseOfTEntity.Delete.cs
│ ├── DalBaseOfTEntity.Execute.OtherConn.cs
│ ├── DalBaseOfTEntity.Execute.cs
│ ├── DalBaseOfTEntity.ExecuteScalar.OtherConn.cs
│ ├── DalBaseOfTEntity.ExecuteScalar.cs
│ ├── DalBaseOfTEntity.Exsit.cs
│ ├── DalBaseOfTEntity.Get.cs
│ ├── DalBaseOfTEntity.GetFirst.cs
│ ├── DalBaseOfTEntity.GetList.cs
│ ├── DalBaseOfTEntity.GetListPaged.cs
│ ├── DalBaseOfTEntity.GetSet.cs
│ ├── DalBaseOfTEntity.GetTop.cs
│ ├── DalBaseOfTEntity.Insert.cs
│ ├── DalBaseOfTEntity.Query.OtherConn.cs
│ ├── DalBaseOfTEntity.Query.cs
│ ├── DalBaseOfTEntity.QueryDataSet.OtherConn.cs
│ ├── DalBaseOfTEntity.QueryDataSet.cs
│ ├── DalBaseOfTEntity.QueryFirst.OtherConn.cs
│ ├── DalBaseOfTEntity.QueryFirst.cs
│ ├── DalBaseOfTEntity.QueryMultiple.OtherConn.cs
│ ├── DalBaseOfTEntity.QueryMultiple.cs
│ ├── DalBaseOfTEntity.SoftDelete.cs
│ ├── DalBaseOfTEntity.SwitchActive.cs
│ ├── DalBaseOfTEntity.Update.cs
│ ├── DalBaseOfTEntity.cs
│ ├── DalConfiguration.cs
│ ├── DalOptions.cs
│ ├── DapperDal.csproj
│ ├── Expressions
│ ├── ExpressionUtility.cs
│ ├── PredicateBuilder.cs
│ ├── PredicateExtensions.cs
│ ├── QueryBuilder.cs
│ ├── QueryFunctions.cs
│ ├── SortDirection.cs
│ └── SortingExtensions.cs
│ ├── Implementor
│ └── DalImplementor.cs
│ ├── Mapper
│ ├── AutoClassMapper.cs
│ ├── AutoEntityMapper.cs
│ ├── ClassMapper.cs
│ ├── PluralizedAutoClassMapper.cs
│ └── PropertyMap.cs
│ ├── Predicate
│ ├── GetMultiplePredicate.cs
│ ├── GetMultipleResult.cs
│ └── Predicates.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── Sql
│ ├── SqlDialectBase.cs
│ ├── SqlGenerator.cs
│ └── SqlServerDialect.cs
│ ├── Utils
│ ├── ExpressionExtensions.cs
│ └── ReflectionHelper.cs
│ └── packages.config
├── test
├── DapperDal.Test.Entities
│ ├── DapperDal.Test.Entities.csproj
│ ├── ExternallyMapped.cs
│ └── Properties
│ │ └── AssemblyInfo.cs
├── DapperDal.Test.Maps
│ ├── DapperDal.Test.Maps.csproj
│ ├── ExternallyMappedMap.cs
│ └── Properties
│ │ └── AssemblyInfo.cs
└── DapperDal.Test
│ ├── App.config
│ ├── Dal
│ ├── CarDal.cs
│ ├── ConnectionNames.cs
│ └── PersonDal.cs
│ ├── DapperDal.Test.csproj
│ ├── Entities
│ ├── CarEntity.cs
│ └── PersonEntity.cs
│ ├── Helpers
│ ├── DatabaseInfo.cs
│ ├── Protected.cs
│ └── TestHelpers.cs
│ ├── IntegrationTests
│ ├── NonCrudFixture.cs
│ └── SqlServer
│ │ ├── CrudFixture.cs
│ │ ├── Sql
│ │ ├── CreateCarTable.sql
│ │ ├── CreateDatabase.sql
│ │ ├── CreatePersonProcedure.sql
│ │ ├── CreatePersonTable.sql
│ │ ├── DropDatabase.sql
│ │ └── TruncateTable.sql
│ │ └── SqlServerBaseFixture.cs
│ ├── Mapper
│ ├── AutoClassMapperFixture.cs
│ ├── ClassMapperFixture.cs
│ ├── PluralizedAutoClassMapperFixture.cs
│ └── PropertyMapFixture.cs
│ ├── PredicatesFixture.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── ReflectionHelperFixture.cs
│ ├── Sql
│ ├── SqlDialectBaseFixture.cs
│ ├── SqlGeneratorFixture.cs
│ └── SqlServerDialectFixture.cs
│ └── packages.config
└── toc.yml
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome:http://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # Don't use tabs for indentation.
7 | [*]
8 | indent_style = space
9 | # (Please don't specify an indent_size here; that has too many unintended consequences.)
10 |
11 | # Code files
12 | [*.{cs,csx,vb,vbx}]
13 | indent_size = 4
14 |
15 | # Xml project files
16 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
17 | indent_size = 2
18 |
19 | # Xml config files
20 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
21 | indent_size = 2
22 |
23 | # JSON files
24 | [*.json]
25 | indent_size = 2
26 |
27 | # Dotnet code style settings:
28 | [*.cs]
29 | # Sort using and Import directives with System.* appearing first
30 | dotnet_sort_system_directives_first = true
31 |
32 | # Don't use this. qualifier
33 | dotnet_style_qualification_for_field = false:suggestion
34 | dotnet_style_qualification_for_property = false:suggestion
35 |
36 | # use int x = .. over Int32
37 | dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
38 |
39 | # use int.MaxValue over Int32.MaxValue
40 | dotnet_style_predefined_type_for_member_access = true:suggestion
41 |
42 | # Require var all the time.
43 | csharp_style_var_for_built_in_types = true:suggestion
44 | csharp_style_var_when_type_is_apparent = true:suggestion
45 | csharp_style_var_elsewhere = true:suggestion
46 |
47 | # Disallow throw expressions.
48 | csharp_style_throw_expression = false:suggestion
49 |
50 | # Newline settings
51 | csharp_new_line_before_open_brace = all
52 | csharp_new_line_before_else = true
53 | csharp_new_line_before_catch = true
54 | csharp_new_line_before_finally = true
55 | csharp_new_line_before_members_in_object_initializers = true
56 | csharp_new_line_before_members_in_anonymous_types = true
57 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.doc diff=astextplain
2 | *.DOC diff=astextplain
3 | *.docx diff=astextplain
4 | *.DOCX diff=astextplain
5 | *.dot diff=astextplain
6 | *.DOT diff=astextplain
7 | *.pdf diff=astextplain
8 | *.PDF diff=astextplain
9 | *.rtf diff=astextplain
10 | *.RTF diff=astextplain
11 |
12 | *.jpg binary
13 | *.png binary
14 | *.gif binary
15 |
16 | *.cs text=auto diff=csharp
17 | *.vb text=auto
18 | *.resx text=auto
19 | *.c text=auto
20 | *.cpp text=auto
21 | *.cxx text=auto
22 | *.h text=auto
23 | *.hxx text=auto
24 | *.py text=auto
25 | *.rb text=auto
26 | *.java text=auto
27 | *.html text=auto
28 | *.htm text=auto
29 | *.css text=auto
30 | *.scss text=auto
31 | *.sass text=auto
32 | *.less text=auto
33 | *.js text=auto
34 | *.lisp text=auto
35 | *.clj text=auto
36 | *.sql text=auto
37 | *.php text=auto
38 | *.lua text=auto
39 | *.m text=auto
40 | *.asm text=auto
41 | *.erl text=auto
42 | *.fs text=auto
43 | *.fsx text=auto
44 | *.hs text=auto
45 |
46 | *.csproj text=auto
47 | *.vbproj text=auto
48 | *.fsproj text=auto
49 | *.dbproj text=auto
50 | *.sln text=auto eol=crlf
51 |
52 | *.sh eol=lf
53 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 | *.VC.VC.opendb
85 |
86 | # Visual Studio profiler
87 | *.psess
88 | *.vsp
89 | *.vspx
90 | *.sap
91 |
92 | # TFS 2012 Local Workspace
93 | $tf/
94 |
95 | # Guidance Automation Toolkit
96 | *.gpState
97 |
98 | # ReSharper is a .NET coding add-in
99 | _ReSharper*/
100 | *.[Rr]e[Ss]harper
101 | *.DotSettings.user
102 |
103 | # JustCode is a .NET coding add-in
104 | .JustCode
105 |
106 | # TeamCity is a build add-in
107 | _TeamCity*
108 |
109 | # DotCover is a Code Coverage Tool
110 | *.dotCover
111 |
112 | # NCrunch
113 | _NCrunch_*
114 | .*crunch*.local.xml
115 | nCrunchTemp_*
116 |
117 | # MightyMoose
118 | *.mm.*
119 | AutoTest.Net/
120 |
121 | # Web workbench (sass)
122 | .sass-cache/
123 |
124 | # Installshield output folder
125 | [Ee]xpress/
126 |
127 | # DocProject is a documentation generator add-in
128 | DocProject/buildhelp/
129 | DocProject/Help/*.HxT
130 | DocProject/Help/*.HxC
131 | DocProject/Help/*.hhc
132 | DocProject/Help/*.hhk
133 | DocProject/Help/*.hhp
134 | DocProject/Help/Html2
135 | DocProject/Help/html
136 |
137 | # Click-Once directory
138 | publish/
139 |
140 | # Publish Web Output
141 | *.[Pp]ublish.xml
142 | *.azurePubxml
143 | # TODO: Comment the next line if you want to checkin your web deploy settings
144 | # but database connection strings (with potential passwords) will be unencrypted
145 | *.pubxml
146 | *.publishproj
147 |
148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
149 | # checkin your Azure Web App publish settings, but sensitive information contained
150 | # in these scripts will be unencrypted
151 | PublishScripts/
152 |
153 | # NuGet Packages
154 | #*.nupkg
155 | # The packages folder can be ignored because of Package Restore
156 | **/packages/*
157 | # except build/, which is used as an MSBuild target.
158 | !**/packages/build/
159 | # Uncomment if necessary however generally it will be regenerated when needed
160 | #!**/packages/repositories.config
161 | # NuGet v3's project.json files produces more ignoreable files
162 | *.nuget.props
163 | *.nuget.targets
164 |
165 | # Microsoft Azure Build Output
166 | csx/
167 | *.build.csdef
168 |
169 | # Microsoft Azure Emulator
170 | ecf/
171 | rcf/
172 |
173 | # Windows Store app package directories and files
174 | AppPackages/
175 | BundleArtifacts/
176 | Package.StoreAssociation.xml
177 | _pkginfo.txt
178 |
179 | # Visual Studio cache files
180 | # files ending in .cache can be ignored
181 | *.[Cc]ache
182 | # but keep track of directories ending in .cache
183 | !*.[Cc]ache/
184 |
185 | # Others
186 | ClientBin/
187 | ~$*
188 | *~
189 | *.dbmdl
190 | *.dbproj.schemaview
191 | *.pfx
192 | *.publishsettings
193 | node_modules/
194 | orleans.codegen.cs
195 |
196 | # Since there are multiple workflows, uncomment next line to ignore bower_components
197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
198 | #bower_components/
199 |
200 | # RIA/Silverlight projects
201 | Generated_Code/
202 |
203 | # Backup & report files from converting an old project file
204 | # to a newer Visual Studio version. Backup files are not needed,
205 | # because we have git ;-)
206 | _UpgradeReport_Files/
207 | Backup*/
208 | UpgradeLog*.XML
209 | UpgradeLog*.htm
210 |
211 | # SQL Server files
212 | *.mdf
213 | *.ldf
214 |
215 | # Business Intelligence projects
216 | *.rdl.data
217 | *.bim.layout
218 | *.bim_*.settings
219 |
220 | # Microsoft Fakes
221 | FakesAssemblies/
222 |
223 | # GhostDoc plugin setting file
224 | *.GhostDoc.xml
225 |
226 | # Node.js Tools for Visual Studio
227 | .ntvs_analysis.dat
228 |
229 | # Visual Studio 6 build log
230 | *.plg
231 |
232 | # Visual Studio 6 workspace options file
233 | *.opt
234 |
235 | # Visual Studio LightSwitch build output
236 | **/*.HTMLClient/GeneratedArtifacts
237 | **/*.DesktopClient/GeneratedArtifacts
238 | **/*.DesktopClient/ModelManifest.xml
239 | **/*.Server/GeneratedArtifacts
240 | **/*.Server/ModelManifest.xml
241 | _Pvt_Extensions
242 |
243 | # Paket dependency manager
244 | .paket/paket.exe
245 | paket-files/
246 |
247 | # FAKE - F# Make
248 | .fake/
249 |
250 | # JetBrains Rider
251 | .idea/
252 | *.sln.iml
253 |
254 | ###############
255 | # folder #
256 | ###############
257 | /**/DROP/
258 | /**/TEMP/
259 | /**/packages/
260 | /**/bin/
261 | /**/obj/
262 | _site
--------------------------------------------------------------------------------
/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbing/DapperDal/bdb0beb99f3479e385bbad9970bbc4dda18ab925/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/.nuget/NuGet.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildProjectDirectory)\..\
5 |
6 |
7 | false
8 |
9 |
10 | false
11 |
12 |
13 | true
14 |
15 |
16 | false
17 |
18 |
19 |
20 |
21 |
22 |
26 |
27 |
28 |
29 |
30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
31 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config"))
32 |
33 |
34 |
35 |
36 | $(SolutionDir).nuget
37 | packages.config
38 |
39 |
40 |
41 |
42 | $(NuGetToolsPath)\NuGet.exe
43 | @(PackageSource)
44 |
45 | "$(NuGetExePath)"
46 | mono --runtime=v4.0.30319 $(NuGetExePath)
47 |
48 | $(TargetDir.Trim('\\'))
49 |
50 | -RequireConsent
51 | -NonInteractive
52 |
53 |
54 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "
55 | $(NuGetCommand) pack "$(ProjectPath)" -Properties Configuration=$(Configuration) $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols
56 |
57 |
58 |
59 | RestorePackages;
60 | $(BuildDependsOn);
61 |
62 |
63 |
64 |
65 | $(BuildDependsOn);
66 | BuildPackage;
67 |
68 |
69 |
70 |
71 |
72 |
73 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
88 |
89 |
92 |
93 |
94 |
95 |
97 |
98 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/DapperDal.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | DapperDal
5 | 1.5.19
6 | DapperDal
7 | arbing
8 | arbing
9 | http://www.apache.org/licenses/LICENSE-2.0
10 | https://github.com/arbing/DapperDal
11 |
12 | false
13 | 基于 Dapper、Dapper-Extensions 构建的微型 ORM 类库,提供一个包含增、删、改、查等常用方法的数据访问层基类,支持用 Lambda 表达式书写查询和更新条件
14 | 基于 Dapper、Dapper-Extensions 构建的微型 ORM 类库,提供一个包含增、删、改、查等常用方法的数据访问层基类,支持用 Lambda 表达式书写查询和更新条件
15 |
16 | 1.5.19
17 | * 逻辑删除方法 SoftDelete、SwitchActive 默认更新字段 UpdateTime = DateTime.Now
18 | 1.5.18
19 | * 添加返回 DataSet 的查询方法:QueryDataSet
20 | 1.5.16
21 | * 重构,合并 Dapper-Extensions 到 DapperDal,然后移除 Dapper-Extensions
22 | 1.5.15
23 | * 删除方法 QueryFirstOrDefault,可以使用 QueryFirst 替换
24 | * 添加重载方法 OpenConnection、Execute、Query, 支持传入其他 DB 连接串
25 | 1.5.14
26 | * 添加逻辑删除或激活方法 SwitchActive
27 | * 删除方法 GetFirstOrDefault,可以使用 GetFirst 替换
28 | * 添加支持主键 ID 的重载方法 Update、Delete
29 | * 配置项 SoftDeleteProp 迁移到 DapperDal 中,新添加配置项 SoftActiveProps
30 | 1.5.13
31 | * 添加谓词表达式组合扩展方法(来自alexfoxgill/ExpressionTools)
32 | 1.5.12
33 | * 优化 Exsit 、Count 方法
34 | 1.5.11
35 | * 优化更新方法,支持传递小写字段名
36 | * 添加判断实体是否存在方法:Exsit
37 | 1.5.10
38 | * 添加逻辑删除方法 SoftDeleteById
39 | 1.5.9
40 | * 添加实体查询方法:GetFirstOrDefault 、QueryFirstOrDefault 、QueryFirst
41 | 1.5.8
42 | * 添加SQL执行方法:Execute 、ExecuteScalar
43 | 1.5.7
44 | * 添加实体查询方法:GetFirst 、GetTop
45 | * 优化实体查询方法,添加实体集合返回前是否要缓冲的设置点
46 | * 优化逻辑删除,添加更新属性及值的设置点
47 | 1.5.6
48 | * 生成查询 SQL 时,添加 WITH (NOLOCK)
49 | * 添加设置项:SQL 输出方法
50 | 1.5.5
51 | * 添加逻辑删除方法 SoftDelete
52 | 1.5.4
53 | * 表达式转换用 QueryBuilder 替换 ExpressionVisitor 实现,以支持多个查询条件
54 | 1.5.3
55 | * 添加支持多个实体查询的 Query 方法
56 | 1.5.2
57 | * 添加更新部分属性的 Update 方法(来自vilix13/Dapper-Extensions)
58 | * 添加使用谓词、匿名对象或 lambda 表达式作条件的 Update 方法
59 | 1.5.1
60 | * 整合 Abp.Dapper,为 Dapper-Extensions 添加 lambda 表达式功能(来自Abp.Dapper)
61 |
62 | Dapper orm sql micro-orm Data DAL Dapper-Extensions Abp.Dapper
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/DapperDal.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26430.12
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DapperDal", "src\DapperDal\DapperDal.csproj", "{64CCA848-7660-43EE-ABAE-91EFFE765E41}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DapperDal.Test", "test\DapperDal.Test\DapperDal.Test.csproj", "{8BF8684B-E2F2-43A3-B5C7-B9C49F1810C5}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FF445554-FEE7-45CD-B9A8-1D1D80D9744F}"
11 | ProjectSection(SolutionItems) = preProject
12 | buildPackage.cmd = buildPackage.cmd
13 | DapperDal.nuspec = DapperDal.nuspec
14 | README.md = README.md
15 | EndProjectSection
16 | EndProject
17 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2AD48036-181F-4A7F-BEF8-33951AC23342}"
18 | EndProject
19 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2E5DF445-A607-4C9F-A786-E92768186801}"
20 | EndProject
21 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DapperDal.Test.Entities", "test\DapperDal.Test.Entities\DapperDal.Test.Entities.csproj", "{1EF2B04A-7E97-4C53-8AFB-D90E815CFB05}"
22 | EndProject
23 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DapperDal.Test.Maps", "test\DapperDal.Test.Maps\DapperDal.Test.Maps.csproj", "{E335BE03-0A91-4A41-8631-71044CC46310}"
24 | EndProject
25 | Global
26 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
27 | Debug|Any CPU = Debug|Any CPU
28 | Release|Any CPU = Release|Any CPU
29 | EndGlobalSection
30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
31 | {64CCA848-7660-43EE-ABAE-91EFFE765E41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32 | {64CCA848-7660-43EE-ABAE-91EFFE765E41}.Debug|Any CPU.Build.0 = Debug|Any CPU
33 | {64CCA848-7660-43EE-ABAE-91EFFE765E41}.Release|Any CPU.ActiveCfg = Release|Any CPU
34 | {64CCA848-7660-43EE-ABAE-91EFFE765E41}.Release|Any CPU.Build.0 = Release|Any CPU
35 | {8BF8684B-E2F2-43A3-B5C7-B9C49F1810C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36 | {8BF8684B-E2F2-43A3-B5C7-B9C49F1810C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
37 | {8BF8684B-E2F2-43A3-B5C7-B9C49F1810C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
38 | {8BF8684B-E2F2-43A3-B5C7-B9C49F1810C5}.Release|Any CPU.Build.0 = Release|Any CPU
39 | {1EF2B04A-7E97-4C53-8AFB-D90E815CFB05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40 | {1EF2B04A-7E97-4C53-8AFB-D90E815CFB05}.Debug|Any CPU.Build.0 = Debug|Any CPU
41 | {1EF2B04A-7E97-4C53-8AFB-D90E815CFB05}.Release|Any CPU.ActiveCfg = Release|Any CPU
42 | {1EF2B04A-7E97-4C53-8AFB-D90E815CFB05}.Release|Any CPU.Build.0 = Release|Any CPU
43 | {E335BE03-0A91-4A41-8631-71044CC46310}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
44 | {E335BE03-0A91-4A41-8631-71044CC46310}.Debug|Any CPU.Build.0 = Debug|Any CPU
45 | {E335BE03-0A91-4A41-8631-71044CC46310}.Release|Any CPU.ActiveCfg = Release|Any CPU
46 | {E335BE03-0A91-4A41-8631-71044CC46310}.Release|Any CPU.Build.0 = Release|Any CPU
47 | EndGlobalSection
48 | GlobalSection(SolutionProperties) = preSolution
49 | HideSolutionNode = FALSE
50 | EndGlobalSection
51 | GlobalSection(NestedProjects) = preSolution
52 | {64CCA848-7660-43EE-ABAE-91EFFE765E41} = {2E5DF445-A607-4C9F-A786-E92768186801}
53 | {8BF8684B-E2F2-43A3-B5C7-B9C49F1810C5} = {2AD48036-181F-4A7F-BEF8-33951AC23342}
54 | {1EF2B04A-7E97-4C53-8AFB-D90E815CFB05} = {2AD48036-181F-4A7F-BEF8-33951AC23342}
55 | {E335BE03-0A91-4A41-8631-71044CC46310} = {2AD48036-181F-4A7F-BEF8-33951AC23342}
56 | EndGlobalSection
57 | EndGlobal
58 |
--------------------------------------------------------------------------------
/api/.gitignore:
--------------------------------------------------------------------------------
1 | ###############
2 | # temp file #
3 | ###############
4 | *.yml
5 |
--------------------------------------------------------------------------------
/api/index.md:
--------------------------------------------------------------------------------
1 | # Api Documentation
2 |
--------------------------------------------------------------------------------
/buildPackage.cmd:
--------------------------------------------------------------------------------
1 | @call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat"
2 | MSBuild src\DapperDal\DapperDal.csproj /t:Clean;Rebuild /p:Configuration=Release
3 | .nuget\nuget.exe pack DapperDal.nuspec /o releases
--------------------------------------------------------------------------------
/docfx.json:
--------------------------------------------------------------------------------
1 | {
2 | "metadata": [{
3 | "src": [{
4 | "files": [
5 | "src/**.csproj"
6 | ],
7 | "exclude": [
8 | "**/obj/**",
9 | "**/bin/**",
10 | "_site/**"
11 | ]
12 | }],
13 | "dest": "api"
14 | }],
15 | "build": {
16 | "content": [{
17 | "files": [
18 | "api/**.yml",
19 | "api/index.md"
20 | ]
21 | },
22 | {
23 | "files": [
24 | "toc.yml",
25 | "*.md"
26 | ],
27 | "exclude": [
28 | "obj/**",
29 | "_site/**"
30 | ]
31 | }
32 | ],
33 | "resource": [{
34 | "files": [
35 | "images/**"
36 | ],
37 | "exclude": [
38 | "obj/**",
39 | "_site/**"
40 | ]
41 | }],
42 | "overwrite": [{
43 | "files": [
44 | "apidoc/**.md"
45 | ],
46 | "exclude": [
47 | "obj/**",
48 | "_site/**"
49 | ]
50 | }],
51 | "dest": "_site",
52 | "globalMetadataFiles": [],
53 | "fileMetadataFiles": [],
54 | "template": [
55 | "default"
56 | ],
57 | "postProcessors": [],
58 | "noLangKeyword": false,
59 | "keepFileLink": false,
60 | "cleanupCacheHistory": false
61 | }
62 | }
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity..cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbing/DapperDal/bdb0beb99f3479e385bbad9970bbc4dda18ab925/src/DapperDal/DalBaseOfTEntity..cs
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.Count.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq.Expressions;
3 | using DapperDal.Expressions;
4 |
5 | namespace DapperDal
6 | {
7 | public partial class DalBase where TEntity : class
8 | {
9 | ///
10 | /// 获取实体条数
11 | ///
12 | /// 实体条数
13 | public virtual int Count()
14 | {
15 | using (var connection = OpenConnection())
16 | {
17 | return Configuration.DalImplementor.Count(
18 | connection: connection,
19 | predicate: null,
20 | transaction: null,
21 | commandTimeout: null);
22 | }
23 | }
24 |
25 | ///
26 | /// 根据条件获取实体条数
27 | /// (条件使用谓词或匿名对象)
28 | ///
29 | /// 条件,使用谓词或匿名对象
30 | /// 实体条数
31 | public virtual int Count(object predicate)
32 | {
33 | using (var connection = OpenConnection())
34 | {
35 | return Configuration.DalImplementor.Count(
36 | connection: connection,
37 | predicate: predicate,
38 | transaction: null,
39 | commandTimeout: null);
40 | }
41 | }
42 |
43 | ///
44 | /// 根据条件获取实体条数
45 | /// (条件使用表达式)
46 | ///
47 | /// 条件,使用表达式
48 | /// 实体条数
49 | public virtual int Count(Expression> predicate)
50 | {
51 | using (var connection = OpenConnection())
52 | {
53 | var predicateGp = predicate.ToPredicateGroup();
54 | return Configuration.DalImplementor.Count(
55 | connection: connection,
56 | predicate: predicateGp,
57 | transaction: null,
58 | commandTimeout: null);
59 | }
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.Delete.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq.Expressions;
3 | using DapperDal.Expressions;
4 | using DapperDal.Predicate;
5 |
6 | namespace DapperDal
7 | {
8 | public partial class DalBase where TEntity : class
9 | {
10 | ///
11 | /// 删除指定实体
12 | ///
13 | /// 实体
14 | /// 删除结果
15 | public virtual bool Delete(TEntity entity)
16 | {
17 | using (var connection = OpenConnection())
18 | {
19 | return Configuration.DalImplementor.Delete(
20 | connection: connection,
21 | entity: entity,
22 | transaction: null,
23 | commandTimeout: null);
24 | }
25 | }
26 |
27 | ///
28 | /// 根据实体主键ID删除指定实体
29 | ///
30 | /// 实体主键ID
31 | /// 删除结果
32 | public virtual bool Delete(TPrimaryKey id)
33 | {
34 | using (var connection = OpenConnection())
35 | {
36 | IPredicate predicate = Configuration.DalImplementor.GetIdPredicate(id);
37 |
38 | return Configuration.DalImplementor.Delete(
39 | connection: connection,
40 | predicate: predicate,
41 | transaction: null,
42 | commandTimeout: null);
43 | }
44 | }
45 |
46 | ///
47 | /// 根据条件删除实体
48 | ///
49 | /// 删除条件
50 | /// 删除结果
51 | public virtual bool Delete(object predicate)
52 | {
53 | using (var connection = OpenConnection())
54 | {
55 | return Configuration.DalImplementor.Delete(
56 | connection: connection,
57 | predicate: predicate,
58 | transaction: null,
59 | commandTimeout: null);
60 | }
61 | }
62 |
63 | ///
64 | /// 根据条件删除实体
65 | ///
66 | /// 删除条件
67 | /// 删除结果
68 | public virtual bool Delete(Expression> predicate)
69 | {
70 | using (var connection = OpenConnection())
71 | {
72 | var predicateGp = predicate.ToPredicateGroup();
73 |
74 | return Configuration.DalImplementor.Delete(
75 | connection: connection,
76 | predicate: predicateGp,
77 | transaction: null,
78 | commandTimeout: null);
79 | }
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.Execute.OtherConn.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Linq;
5 | using System.Text;
6 | using Dapper;
7 |
8 | namespace DapperDal
9 | {
10 | public partial class DalBase where TEntity : class
11 | {
12 | ///
13 | /// 执行SQL语句
14 | ///
15 | /// DB 连接字符串配置节点名
16 | /// SQL语句
17 | /// 影响行数
18 | public virtual int Execute(string connNameOrConnStr, string sql)
19 | {
20 | using (var connection = OpenConnection(connNameOrConnStr))
21 | {
22 | return connection.Execute(sql);
23 | }
24 | }
25 |
26 | ///
27 | /// 执行参数化SQL语句
28 | ///
29 | /// DB 连接字符串配置节点名
30 | /// SQL语句
31 | /// SQL参数
32 | /// 影响行数
33 | public virtual int Execute(string connNameOrConnStr, string sql, object parameters)
34 | {
35 | using (var connection = OpenConnection(connNameOrConnStr))
36 | {
37 | return connection.Execute(sql, parameters);
38 | }
39 | }
40 |
41 | ///
42 | /// 执行参数化SQL语句
43 | ///
44 | /// DB 连接字符串配置节点名
45 | /// SQL语句
46 | /// SQL参数
47 | /// SQL语句命令类型
48 | /// 影响行数
49 | public virtual int Execute(string connNameOrConnStr, string sql, object parameters, CommandType commandType)
50 | {
51 | using (var connection = OpenConnection(connNameOrConnStr))
52 | {
53 | return connection.Execute(sql, parameters, commandType: commandType);
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.Execute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Linq;
5 | using System.Text;
6 | using Dapper;
7 |
8 | namespace DapperDal
9 | {
10 | public partial class DalBase where TEntity : class
11 | {
12 | ///
13 | /// 执行SQL语句
14 | ///
15 | /// SQL语句
16 | /// 影响行数
17 | public virtual int Execute(string sql)
18 | {
19 | using (var connection = OpenConnection())
20 | {
21 | return connection.Execute(sql);
22 | }
23 | }
24 |
25 | ///
26 | /// 执行参数化SQL语句
27 | ///
28 | /// SQL语句
29 | /// SQL参数
30 | /// 影响行数
31 | public virtual int Execute(string sql, object parameters)
32 | {
33 | using (var connection = OpenConnection())
34 | {
35 | return connection.Execute(sql, parameters);
36 | }
37 | }
38 |
39 | ///
40 | /// 执行参数化SQL语句
41 | ///
42 | /// SQL语句
43 | /// SQL参数
44 | /// SQL语句命令类型
45 | /// 影响行数
46 | public virtual int Execute(string sql, object parameters, CommandType commandType)
47 | {
48 | using (var connection = OpenConnection())
49 | {
50 | return connection.Execute(sql, parameters, commandType: commandType);
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.ExecuteScalar.OtherConn.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Linq;
5 | using System.Text;
6 | using Dapper;
7 |
8 | namespace DapperDal
9 | {
10 | public partial class DalBase where TEntity : class
11 | {
12 | ///
13 | /// 执行SQL语句,返回第一行第一列数据
14 | ///
15 | /// 返回数据类型
16 | /// DB 连接字符串配置节点名
17 | /// SQL语句
18 | /// 第一行第一列数据
19 | public virtual TAny ExecuteScalar(string connNameOrConnStr, string sql)
20 | {
21 | using (var connection = OpenConnection(connNameOrConnStr))
22 | {
23 | return connection.ExecuteScalar(sql);
24 | }
25 | }
26 |
27 | ///
28 | /// 执行参数化SQL语句,返回第一行第一列数据
29 | ///
30 | /// 返回数据类型
31 | /// DB 连接字符串配置节点名
32 | /// SQL语句
33 | /// SQL参数
34 | /// 第一行第一列数据
35 | public virtual TAny ExecuteScalar(string connNameOrConnStr, string sql, object parameters)
36 | {
37 | using (var connection = OpenConnection(connNameOrConnStr))
38 | {
39 | return connection.ExecuteScalar(sql, parameters);
40 | }
41 | }
42 |
43 | ///
44 | /// 执行参数化SQL语句,返回第一行第一列数据
45 | ///
46 | /// 返回数据类型
47 | /// DB 连接字符串配置节点名
48 | /// SQL语句
49 | /// SQL参数
50 | /// SQL语句命令类型
51 | /// 第一行第一列数据
52 | public virtual TAny ExecuteScalar(string connNameOrConnStr, string sql, object parameters, CommandType commandType)
53 | {
54 | using (var connection = OpenConnection(connNameOrConnStr))
55 | {
56 | return connection.ExecuteScalar(sql, parameters, commandType: commandType);
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.ExecuteScalar.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Linq;
5 | using System.Text;
6 | using Dapper;
7 |
8 | namespace DapperDal
9 | {
10 | public partial class DalBase where TEntity : class
11 | {
12 | ///
13 | /// 执行SQL语句,返回第一行第一列数据
14 | ///
15 | /// 返回数据类型
16 | /// SQL语句
17 | /// 第一行第一列数据
18 | public virtual TAny ExecuteScalar(string sql)
19 | {
20 | using (var connection = OpenConnection())
21 | {
22 | return connection.ExecuteScalar(sql);
23 | }
24 | }
25 |
26 | ///
27 | /// 执行参数化SQL语句,返回第一行第一列数据
28 | ///
29 | /// 返回数据类型
30 | /// SQL语句
31 | /// SQL参数
32 | /// 第一行第一列数据
33 | public virtual TAny ExecuteScalar(string sql, object parameters)
34 | {
35 | using (var connection = OpenConnection())
36 | {
37 | return connection.ExecuteScalar(sql, parameters);
38 | }
39 | }
40 |
41 | ///
42 | /// 执行参数化SQL语句,返回第一行第一列数据
43 | ///
44 | /// 返回数据类型
45 | /// SQL语句
46 | /// SQL参数
47 | /// SQL语句命令类型
48 | /// 第一行第一列数据
49 | public virtual TAny ExecuteScalar(string sql, object parameters, CommandType commandType)
50 | {
51 | using (var connection = OpenConnection())
52 | {
53 | return connection.ExecuteScalar(sql, parameters, commandType: commandType);
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.Exsit.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq.Expressions;
3 | using DapperDal.Expressions;
4 | using DapperDal.Predicate;
5 |
6 | namespace DapperDal
7 | {
8 | public partial class DalBase where TEntity : class
9 | {
10 | ///
11 | /// 判断实体是否存在
12 | ///
13 | /// 是否存在
14 | public virtual bool Exsit()
15 | {
16 | using (var connection = OpenConnection())
17 | {
18 | return Configuration.DalImplementor.Count(
19 | connection: connection,
20 | predicate: null,
21 | transaction: null,
22 | commandTimeout: null) > 0;
23 | }
24 | }
25 |
26 | ///
27 | /// 判断指定主键ID的实体是否存在
28 | ///
29 | /// 实体主键ID
30 | /// 是否存在
31 | public virtual bool Exsit(TPrimaryKey id)
32 | {
33 | using (var connection = OpenConnection())
34 | {
35 | IPredicate predicate = Configuration.DalImplementor.GetIdPredicate(id);
36 | return Configuration.DalImplementor.Count(
37 | connection: connection,
38 | predicate: predicate,
39 | transaction: null,
40 | commandTimeout: null) > 0;
41 | }
42 | }
43 |
44 | ///
45 | /// 判断指定条件的实体是否存在
46 | /// (条件使用谓词或匿名对象)
47 | ///
48 | /// 条件,使用谓词或匿名对象
49 | /// 是否存在
50 | public virtual bool Exsit(object predicate)
51 | {
52 | using (var connection = OpenConnection())
53 | {
54 | return Configuration.DalImplementor.Count(
55 | connection: connection,
56 | predicate: predicate,
57 | transaction: null,
58 | commandTimeout: null) > 0;
59 | }
60 | }
61 |
62 | ///
63 | /// 判断指定条件的实体是否存在
64 | /// (条件使用表达式)
65 | ///
66 | /// 条件,使用表达式
67 | /// 是否存在
68 | public virtual bool Exsit(Expression> predicate)
69 | {
70 | using (var connection = OpenConnection())
71 | {
72 | var predicateGp = predicate.ToPredicateGroup();
73 | return Configuration.DalImplementor.Count(
74 | connection: connection,
75 | predicate: predicateGp,
76 | transaction: null,
77 | commandTimeout: null) > 0;
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.Get.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 | using System.Text;
6 |
7 | namespace DapperDal
8 | {
9 | public partial class DalBase where TEntity : class
10 | {
11 | ///
12 | /// 根据实体ID(主键)获取实体
13 | ///
14 | /// 实体ID
15 | /// 实体
16 | public virtual TEntity Get(TPrimaryKey id)
17 | {
18 | using (var connection = OpenConnection())
19 | {
20 | return Configuration.DalImplementor.Get(
21 | connection: connection,
22 | id: id,
23 | transaction: null,
24 | commandTimeout: null);
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.GetList.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq.Expressions;
4 | using DapperDal.Expressions;
5 |
6 | namespace DapperDal
7 | {
8 | public partial class DalBase where TEntity : class
9 | {
10 | ///
11 | /// 获取所有实体列表
12 | ///
13 | /// 实体列表
14 | public virtual IEnumerable GetList()
15 | {
16 | using (var connection = OpenConnection())
17 | {
18 | return Configuration.DalImplementor.GetList(
19 | connection: connection,
20 | predicate: null,
21 | sort: null,
22 | transaction: null,
23 | commandTimeout: null,
24 | buffered: Configuration.Buffered);
25 | }
26 | }
27 |
28 | ///
29 | /// 根据查询条件获取实体列表
30 | /// (查询使用谓词或匿名对象)
31 | ///
32 | /// 查询条件
33 | /// 实体列表
34 | public virtual IEnumerable GetList(object predicate)
35 | {
36 | using (var connection = OpenConnection())
37 | {
38 | return Configuration.DalImplementor.GetList(
39 | connection: connection,
40 | predicate: predicate,
41 | sort: null,
42 | transaction: null,
43 | commandTimeout: null,
44 | buffered: Configuration.Buffered);
45 | }
46 | }
47 |
48 | ///
49 | /// 根据排序条件获取所有实体列表
50 | /// (排序使用表达式)
51 | ///
52 | /// 排序方向
53 | /// 排序字段
54 | /// 实体列表
55 | public virtual IEnumerable GetList(SortDirection ascending,
56 | params Expression>[] sortingExpression)
57 | {
58 | using (var connection = OpenConnection())
59 | {
60 | var sort = sortingExpression.ToSortable(ascending);
61 | return Configuration.DalImplementor.GetList(
62 | connection: connection,
63 | predicate: null,
64 | sort: sort,
65 | transaction: null,
66 | commandTimeout: null,
67 | buffered: Configuration.Buffered);
68 | }
69 | }
70 |
71 | ///
72 | /// 根据查询条件和排序条件获取实体列表
73 | /// (查询使用谓词或匿名对象,排序使用Sort或匿名对象)
74 | ///
75 | /// 查询条件
76 | /// 排序条件
77 | /// 实体列表
78 | public virtual IEnumerable GetList(object predicate, object sort)
79 | {
80 | using (var connection = OpenConnection())
81 | {
82 | var sorts = sort.ToSortable();
83 | return Configuration.DalImplementor.GetList(
84 | connection: connection,
85 | predicate: predicate,
86 | sort: sorts,
87 | transaction: null,
88 | commandTimeout: null,
89 | buffered: Configuration.Buffered);
90 | }
91 | }
92 |
93 | ///
94 | /// 根据查询条件和排序条件获取实体列表
95 | /// (查询使用谓词或匿名对象,排序使用表达式)
96 | ///
97 | /// 查询条件
98 | /// 排序方向
99 | /// 排序字段
100 | /// 实体列表
101 | public virtual IEnumerable GetList(object predicate,
102 | SortDirection ascending,
103 | params Expression>[] sortingExpression)
104 | {
105 | using (var connection = OpenConnection())
106 | {
107 | var sort = sortingExpression.ToSortable(ascending);
108 | return Configuration.DalImplementor.GetList(
109 | connection: connection,
110 | predicate: predicate,
111 | sort: sort,
112 | transaction: null,
113 | commandTimeout: null,
114 | buffered: Configuration.Buffered);
115 | }
116 | }
117 |
118 | ///
119 | /// 根据查询条件获取实体列表
120 | /// (查询使用表达式)
121 | ///
122 | /// 查询条件
123 | /// 实体列表
124 | public virtual IEnumerable GetList(Expression> predicate)
125 | {
126 | using (var connection = OpenConnection())
127 | {
128 | var predicateGp = predicate.ToPredicateGroup();
129 | return Configuration.DalImplementor.GetList(
130 | connection: connection,
131 | predicate: predicateGp,
132 | sort: null,
133 | transaction: null,
134 | commandTimeout: null,
135 | buffered: Configuration.Buffered);
136 | }
137 | }
138 |
139 | ///
140 | /// 根据查询条件和排序条件获取实体列表
141 | /// (查询使用表达式,排序使用Sort或匿名对象)
142 | ///
143 | /// 查询条件
144 | /// 排序条件
145 | /// 实体列表
146 | public virtual IEnumerable GetList(Expression> predicate, object sort)
147 | {
148 | using (var connection = OpenConnection())
149 | {
150 | var predicateGp = predicate.ToPredicateGroup();
151 | var sorts = sort.ToSortable();
152 | return Configuration.DalImplementor.GetList(
153 | connection: connection,
154 | predicate: predicateGp,
155 | sort: sorts,
156 | transaction: null,
157 | commandTimeout: null,
158 | buffered: Configuration.Buffered);
159 | }
160 | }
161 |
162 | ///
163 | /// 根据查询条件和排序条件获取实体列表
164 | /// (查询使用表达式,排序使用表达式)
165 | ///
166 | /// 查询条件
167 | /// 排序方向
168 | /// 排序字段
169 | /// 实体列表
170 | public virtual IEnumerable GetList(Expression> predicate,
171 | SortDirection ascending,
172 | params Expression>[] sortingExpression)
173 | {
174 | using (var connection = OpenConnection())
175 | {
176 | var predicateGp = predicate.ToPredicateGroup();
177 | var sort = sortingExpression.ToSortable(ascending);
178 | return Configuration.DalImplementor.GetList(
179 | connection: connection,
180 | predicate: predicateGp,
181 | sort: sort,
182 | transaction: null,
183 | commandTimeout: null,
184 | buffered: Configuration.Buffered);
185 | }
186 | }
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.GetListPaged.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq.Expressions;
4 | using DapperDal.Expressions;
5 |
6 | namespace DapperDal
7 | {
8 | public partial class DalBase where TEntity : class
9 | {
10 | ///
11 | /// 根据查询条件和排序条件获取实体分页列表
12 | /// (查询使用谓词或匿名对象,排序使用Sort或匿名对象)
13 | ///
14 | /// 查询条件
15 | /// 排序条件
16 | /// 页号,从1起始
17 | /// 每页条数
18 | /// 实体分页列表
19 | public virtual IEnumerable GetListPaged(object predicate, object sort,
20 | int pageNumber, int itemsPerPage)
21 | {
22 | using (var connection = OpenConnection())
23 | {
24 | var sorts = sort.ToSortable();
25 | return Configuration.DalImplementor.GetPage(
26 | connection: connection,
27 | predicate: predicate,
28 | sort: sorts,
29 | page: pageNumber - 1,
30 | resultsPerPage: itemsPerPage,
31 | transaction: null,
32 | commandTimeout: null,
33 | buffered: Configuration.Buffered);
34 | }
35 | }
36 |
37 | ///
38 | /// 根据查询条件和排序条件获取实体分页列表
39 | /// (查询使用谓词或匿名对象,排序表达式)
40 | ///
41 | /// 查询条件
42 | /// 页号,从1起始
43 | /// 每页条数
44 | /// 排序方向
45 | /// 排序字段
46 | /// 实体分页列表
47 | public virtual IEnumerable GetListPaged(object predicate,
48 | int pageNumber, int itemsPerPage,
49 | SortDirection ascending,
50 | params Expression>[] sortingExpression)
51 | {
52 | using (var connection = OpenConnection())
53 | {
54 | var sort = sortingExpression.ToSortable(ascending);
55 | return Configuration.DalImplementor.GetPage(
56 | connection: connection,
57 | predicate: predicate,
58 | sort: sort,
59 | page: pageNumber - 1,
60 | resultsPerPage: itemsPerPage,
61 | transaction: null,
62 | commandTimeout: null,
63 | buffered: Configuration.Buffered);
64 | }
65 | }
66 |
67 | ///
68 | /// 根据查询条件和排序条件获取实体分页列表
69 | /// (查询使用表达式,排序使用Sort或匿名对象)
70 | ///
71 | /// 查询条件
72 | /// 排序条件
73 | /// 页号,从1起始
74 | /// 每页条数
75 | /// 实体分页列表
76 | public virtual IEnumerable GetListPaged(Expression> predicate, object sort,
77 | int pageNumber, int itemsPerPage)
78 | {
79 | using (var connection = OpenConnection())
80 | {
81 | var predicateGp = predicate.ToPredicateGroup();
82 | var sorts = sort.ToSortable();
83 | return Configuration.DalImplementor.GetPage(
84 | connection: connection,
85 | predicate: predicateGp,
86 | sort: sorts,
87 | page: pageNumber - 1,
88 | resultsPerPage: itemsPerPage,
89 | transaction: null,
90 | commandTimeout: null,
91 | buffered: Configuration.Buffered);
92 | }
93 | }
94 |
95 | ///
96 | /// 根据查询条件和排序条件获取实体分页列表
97 | /// (查询使用表达式,排序使用表达式)
98 | ///
99 | /// 查询条件
100 | /// 页号,从1起始
101 | /// 每页条数
102 | /// 排序方向
103 | /// 排序字段
104 | /// 实体分页列表
105 | public virtual IEnumerable GetListPaged(Expression> predicate,
106 | int pageNumber, int itemsPerPage,
107 | SortDirection ascending,
108 | params Expression>[] sortingExpression)
109 | {
110 | using (var connection = OpenConnection())
111 | {
112 | var predicateGp = predicate.ToPredicateGroup();
113 | var sort = sortingExpression.ToSortable(ascending);
114 | return Configuration.DalImplementor.GetPage(
115 | connection: connection,
116 | predicate: predicateGp,
117 | sort: sort,
118 | page: pageNumber - 1,
119 | resultsPerPage: itemsPerPage,
120 | transaction: null,
121 | commandTimeout: null,
122 | buffered: Configuration.Buffered);
123 | }
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.GetSet.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq.Expressions;
4 | using DapperDal.Expressions;
5 |
6 | namespace DapperDal
7 | {
8 | public partial class DalBase where TEntity : class
9 | {
10 | ///
11 | /// 根据查询条件和排序条件获取实体区间列表
12 | /// (查询使用谓词或匿名对象,排序使用Sort或匿名对象)
13 | ///
14 | /// 查询条件
15 | /// 排序条件
16 | /// 起始行数
17 | /// 最大条数
18 | /// 实体区间列表
19 | public virtual IEnumerable GetSet(object predicate, object sort,
20 | int firstResult, int maxResults)
21 | {
22 | using (var connection = OpenConnection())
23 | {
24 | var sorts = sort.ToSortable();
25 | return Configuration.DalImplementor.GetSet(
26 | connection: connection,
27 | predicate: predicate,
28 | sort: sorts,
29 | firstResult: firstResult,
30 | maxResults: maxResults,
31 | transaction: null,
32 | commandTimeout: null,
33 | buffered: Configuration.Buffered);
34 | }
35 | }
36 |
37 | ///
38 | /// 根据查询条件和排序条件获取实体区间列表
39 | /// (查询使用谓词或匿名对象,排序表达式)
40 | ///
41 | /// 查询条件
42 | /// 起始行数
43 | /// 最大条数
44 | /// 排序方向
45 | /// 排序字段
46 | /// 实体区间列表
47 | public virtual IEnumerable GetSet(object predicate,
48 | int firstResult, int maxResults,
49 | SortDirection ascending,
50 | params Expression>[] sortingExpression)
51 | {
52 | using (var connection = OpenConnection())
53 | {
54 | var sort = sortingExpression.ToSortable(ascending);
55 | return Configuration.DalImplementor.GetSet(
56 | connection: connection,
57 | predicate: predicate,
58 | sort: sort,
59 | firstResult: firstResult,
60 | maxResults: maxResults,
61 | transaction: null,
62 | commandTimeout: null,
63 | buffered: Configuration.Buffered);
64 | }
65 | }
66 |
67 | ///
68 | /// 根据查询条件和排序条件获取实体区间列表
69 | /// (查询使用表达式,排序使用Sort或匿名对象)
70 | ///
71 | /// 查询条件
72 | /// 排序条件
73 | /// 起始行数
74 | /// 最大条数
75 | /// 实体区间列表
76 | public virtual IEnumerable GetSet(Expression> predicate, object sort,
77 | int firstResult, int maxResults)
78 | {
79 | using (var connection = OpenConnection())
80 | {
81 | var predicateGp = predicate.ToPredicateGroup();
82 | var sorts = sort.ToSortable();
83 | return Configuration.DalImplementor.GetSet(
84 | connection: connection,
85 | predicate: predicateGp,
86 | sort: sorts,
87 | firstResult: firstResult,
88 | maxResults: maxResults,
89 | transaction: null,
90 | commandTimeout: null,
91 | buffered: Configuration.Buffered);
92 | }
93 | }
94 |
95 | ///
96 | /// 根据查询条件和排序条件获取实体区间列表
97 | /// (查询使用表达式,排序使用表达式)
98 | ///
99 | /// 查询条件
100 | /// 起始行数
101 | /// 最大条数
102 | /// 排序方向
103 | /// 排序字段
104 | /// 实体区间列表
105 | public virtual IEnumerable GetSet(Expression> predicate,
106 | int firstResult, int maxResults,
107 | SortDirection ascending,
108 | params Expression>[] sortingExpression)
109 | {
110 | using (var connection = OpenConnection())
111 | {
112 | var predicateGp = predicate.ToPredicateGroup();
113 | var sort = sortingExpression.ToSortable(ascending);
114 | return Configuration.DalImplementor.GetSet(
115 | connection: connection,
116 | predicate: predicateGp,
117 | sort: sort,
118 | firstResult: firstResult,
119 | maxResults: maxResults,
120 | transaction: null,
121 | commandTimeout: null,
122 | buffered: Configuration.Buffered);
123 | }
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.Insert.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 | using System.Text;
6 |
7 | namespace DapperDal
8 | {
9 | public partial class DalBase where TEntity : class
10 | {
11 | ///
12 | /// 插入指定实体
13 | ///
14 | /// 实体
15 | /// 实体主键
16 | public virtual TPrimaryKey Insert(TEntity entity)
17 | {
18 | using (var connection = OpenConnection())
19 | {
20 | return Configuration.DalImplementor.Insert(
21 | connection: connection,
22 | entity: entity,
23 | transaction: null,
24 | commandTimeout: null);
25 | }
26 | }
27 |
28 | ///
29 | /// 批量插入指定实体集合
30 | ///
31 | /// 实体集合
32 | public virtual void Insert(IEnumerable entities)
33 | {
34 | using (var connection = OpenConnection())
35 | {
36 | Configuration.DalImplementor.Insert(
37 | connection: connection,
38 | entities: entities,
39 | transaction: null,
40 | commandTimeout: null);
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.Query.OtherConn.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Linq;
5 | using System.Text;
6 | using Dapper;
7 |
8 | namespace DapperDal
9 | {
10 | public partial class DalBase where TEntity : class
11 | {
12 | ///
13 | /// 使用SQL语句获取实体集合
14 | ///
15 | /// DB 连接字符串配置节点名
16 | /// SQL语句
17 | /// 实体集合
18 | public virtual IEnumerable Query(string connNameOrConnStr, string sql)
19 | {
20 | using (var connection = OpenConnection(connNameOrConnStr))
21 | {
22 | return connection.Query(sql);
23 | }
24 | }
25 |
26 | ///
27 | /// 使用SQL语句获取实体集合
28 | ///
29 | /// DB 连接字符串配置节点名
30 | /// SQL语句
31 | /// SQL参数
32 | /// 实体集合
33 | public virtual IEnumerable Query(string connNameOrConnStr, string sql, object parameters)
34 | {
35 | using (var connection = OpenConnection(connNameOrConnStr))
36 | {
37 | return connection.Query(sql, parameters);
38 | }
39 | }
40 |
41 | ///
42 | /// 使用SQL语句获取实体集合
43 | ///
44 | /// DB 连接字符串配置节点名
45 | /// SQL语句
46 | /// SQL参数
47 | /// SQL语句命令类型
48 | /// 实体集合
49 | public virtual IEnumerable Query(string connNameOrConnStr, string sql, object parameters, CommandType commandType)
50 | {
51 | using (var connection = OpenConnection(connNameOrConnStr))
52 | {
53 | return connection.Query(sql, parameters, commandType: commandType);
54 | }
55 | }
56 |
57 | ///
58 | /// 使用SQL语句获取指定实体集合
59 | ///
60 | /// 返回实体类型
61 | /// DB 连接字符串配置节点名
62 | /// SQL语句
63 | /// 实体集合
64 | public virtual IEnumerable Query(string connNameOrConnStr, string sql)
65 | {
66 | using (var connection = OpenConnection(connNameOrConnStr))
67 | {
68 | return connection.Query(sql);
69 | }
70 | }
71 |
72 | ///
73 | /// 使用SQL语句获取指定实体集合
74 | ///
75 | /// 返回实体类型
76 | /// DB 连接字符串配置节点名
77 | /// SQL语句
78 | /// SQL参数
79 | /// 实体集合
80 | public virtual IEnumerable Query(string connNameOrConnStr, string sql, object parameters)
81 | {
82 | using (var connection = OpenConnection(connNameOrConnStr))
83 | {
84 | return connection.Query(sql, parameters);
85 | }
86 | }
87 |
88 | ///
89 | /// 使用SQL语句获取指定实体集合
90 | ///
91 | /// 返回实体类型
92 | /// DB 连接字符串配置节点名
93 | /// SQL语句
94 | /// SQL参数
95 | /// SQL语句命令类型
96 | /// 实体集合
97 | public virtual IEnumerable Query(string connNameOrConnStr, string sql, object parameters, CommandType commandType)
98 | {
99 | using (var connection = OpenConnection(connNameOrConnStr))
100 | {
101 | return connection.Query(sql, parameters, commandType: commandType);
102 | }
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.Query.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Linq;
5 | using System.Text;
6 | using Dapper;
7 |
8 | namespace DapperDal
9 | {
10 | public partial class DalBase where TEntity : class
11 | {
12 | ///
13 | /// 使用SQL语句获取实体集合
14 | ///
15 | /// SQL语句
16 | /// 实体集合
17 | public virtual IEnumerable Query(string sql)
18 | {
19 | using (var connection = OpenConnection())
20 | {
21 | return connection.Query(sql);
22 | }
23 | }
24 |
25 | ///
26 | /// 使用SQL语句获取实体集合
27 | ///
28 | /// SQL语句
29 | /// SQL参数
30 | /// 实体集合
31 | public virtual IEnumerable Query(string sql, object parameters)
32 | {
33 | using (var connection = OpenConnection())
34 | {
35 | return connection.Query(sql, parameters);
36 | }
37 | }
38 |
39 | ///
40 | /// 使用SQL语句获取实体集合
41 | ///
42 | /// SQL语句
43 | /// SQL参数
44 | /// SQL语句命令类型
45 | /// 实体集合
46 | public virtual IEnumerable Query(string sql, object parameters, CommandType commandType)
47 | {
48 | using (var connection = OpenConnection())
49 | {
50 | return connection.Query(sql, parameters, commandType: commandType);
51 | }
52 | }
53 |
54 | ///
55 | /// 使用SQL语句获取指定实体集合
56 | ///
57 | /// 返回实体类型
58 | /// SQL语句
59 | /// 实体集合
60 | public virtual IEnumerable Query(string sql)
61 | {
62 | using (var connection = OpenConnection())
63 | {
64 | return connection.Query(sql);
65 | }
66 | }
67 |
68 | ///
69 | /// 使用SQL语句获取指定实体集合
70 | ///
71 | /// 返回实体类型
72 | /// SQL语句
73 | /// SQL参数
74 | /// 实体集合
75 | public virtual IEnumerable Query(string sql, object parameters)
76 | {
77 | using (var connection = OpenConnection())
78 | {
79 | return connection.Query(sql, parameters);
80 | }
81 | }
82 |
83 | ///
84 | /// 使用SQL语句获取指定实体集合
85 | ///
86 | /// 返回实体类型
87 | /// SQL语句
88 | /// SQL参数
89 | /// SQL语句命令类型
90 | /// 实体集合
91 | public virtual IEnumerable Query(string sql, object parameters, CommandType commandType)
92 | {
93 | using (var connection = OpenConnection())
94 | {
95 | return connection.Query(sql, parameters, commandType: commandType);
96 | }
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.QueryDataSet.OtherConn.cs:
--------------------------------------------------------------------------------
1 | using System.Data;
2 | using Dapper;
3 |
4 | namespace DapperDal
5 | {
6 | public partial class DalBase where TEntity : class
7 | {
8 | ///
9 | /// 执行 SQL 语句返回 DataSet
10 | ///
11 | /// DB 连接字符串配置节点名
12 | /// SQL语句
13 | /// DataSet
14 | public virtual DataSet QueryDataSet(string connNameOrConnStr, string sql)
15 | {
16 | using (var connection = OpenConnection(connNameOrConnStr))
17 | {
18 | using (var reader = connection.ExecuteReader(sql))
19 | {
20 | DataSet ds = new DataSet();
21 |
22 | while (!reader.IsClosed)
23 | {
24 | ds.Tables.Add().Load(reader);
25 | }
26 |
27 | return ds;
28 | }
29 | }
30 | }
31 |
32 | ///
33 | /// 执行 SQL 语句返回 DataSet
34 | ///
35 | /// DB 连接字符串配置节点名
36 | /// SQL语句
37 | /// SQL参数
38 | /// DataSet
39 | public virtual DataSet QueryDataSet(string connNameOrConnStr, string sql, object parameters)
40 | {
41 | using (var connection = OpenConnection(connNameOrConnStr))
42 | {
43 | using (var reader = connection.ExecuteReader(sql, parameters))
44 | {
45 | DataSet ds = new DataSet();
46 |
47 | while (!reader.IsClosed)
48 | {
49 | ds.Tables.Add().Load(reader);
50 | }
51 |
52 | return ds;
53 | }
54 | }
55 | }
56 |
57 | ///
58 | /// 执行 SQL 语句返回 DataSet
59 | ///
60 | /// DB 连接字符串配置节点名
61 | /// SQL语句
62 | /// SQL参数
63 | /// SQL语句命令类型
64 | /// DataSet
65 | public virtual DataSet QueryDataSet(string connNameOrConnStr, string sql, object parameters,
66 | CommandType commandType)
67 | {
68 | using (var connection = OpenConnection(connNameOrConnStr))
69 | {
70 | using (var reader = connection.ExecuteReader(sql, parameters, commandType: commandType))
71 | {
72 | DataSet ds = new DataSet();
73 |
74 | while (!reader.IsClosed)
75 | {
76 | ds.Tables.Add().Load(reader);
77 | }
78 |
79 | return ds;
80 | }
81 | }
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.QueryDataSet.cs:
--------------------------------------------------------------------------------
1 | using System.Data;
2 | using Dapper;
3 |
4 | namespace DapperDal
5 | {
6 | public partial class DalBase where TEntity : class
7 | {
8 | ///
9 | /// 执行 SQL 语句返回 DataSet
10 | ///
11 | /// SQL语句
12 | /// DataSet
13 | public virtual DataSet QueryDataSet(string sql)
14 | {
15 | using (var connection = OpenConnection())
16 | {
17 | using (var reader = connection.ExecuteReader(sql))
18 | {
19 | DataSet ds = new DataSet();
20 |
21 | while (!reader.IsClosed)
22 | {
23 | ds.Tables.Add().Load(reader);
24 | }
25 |
26 | return ds;
27 | }
28 | }
29 | }
30 |
31 | ///
32 | /// 执行 SQL 语句返回 DataSet
33 | ///
34 | /// SQL语句
35 | /// SQL参数
36 | /// DataSet
37 | public virtual DataSet QueryDataSet(string sql, object parameters)
38 | {
39 | using (var connection = OpenConnection())
40 | {
41 | using (var reader = connection.ExecuteReader(sql, parameters))
42 | {
43 | DataSet ds = new DataSet();
44 |
45 | while (!reader.IsClosed)
46 | {
47 | ds.Tables.Add().Load(reader);
48 | }
49 |
50 | return ds;
51 | }
52 | }
53 | }
54 |
55 | ///
56 | /// 执行 SQL 语句返回 DataSet
57 | ///
58 | /// SQL语句
59 | /// SQL参数
60 | /// SQL语句命令类型
61 | /// DataSet
62 | public virtual DataSet QueryDataSet(string sql, object parameters, CommandType commandType)
63 | {
64 | using (var connection = OpenConnection())
65 | {
66 | using (var reader = connection.ExecuteReader(sql, parameters, commandType: commandType))
67 | {
68 | DataSet ds = new DataSet();
69 |
70 | while (!reader.IsClosed)
71 | {
72 | ds.Tables.Add().Load(reader);
73 | }
74 |
75 | return ds;
76 | }
77 | }
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.QueryFirst.OtherConn.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Linq;
5 | using System.Text;
6 | using Dapper;
7 |
8 | namespace DapperDal
9 | {
10 | public partial class DalBase where TEntity : class
11 | {
12 | ///
13 | /// 使用SQL语句获取实体
14 | ///
15 | /// DB 连接字符串配置节点名
16 | /// SQL语句
17 | /// 实体
18 | public virtual TEntity QueryFirst(string connNameOrConnStr, string sql)
19 | {
20 | using (var connection = OpenConnection(connNameOrConnStr))
21 | {
22 | return connection.QueryFirstOrDefault(sql);
23 | }
24 | }
25 |
26 | ///
27 | /// 使用SQL语句获取实体
28 | ///
29 | /// DB 连接字符串配置节点名
30 | /// SQL语句
31 | /// SQL参数
32 | /// 实体
33 | public virtual TEntity QueryFirst(string connNameOrConnStr, string sql, object parameters)
34 | {
35 | using (var connection = OpenConnection(connNameOrConnStr))
36 | {
37 | return connection.QueryFirstOrDefault(sql, parameters);
38 | }
39 | }
40 |
41 | ///
42 | /// 使用SQL语句获取实体
43 | ///
44 | /// DB 连接字符串配置节点名
45 | /// SQL语句
46 | /// SQL参数
47 | /// SQL语句命令类型
48 | /// 实体
49 | public virtual TEntity QueryFirst(string connNameOrConnStr, string sql, object parameters, CommandType commandType)
50 | {
51 | using (var connection = OpenConnection(connNameOrConnStr))
52 | {
53 | return connection.QueryFirstOrDefault(sql, parameters, commandType: commandType);
54 | }
55 | }
56 |
57 | ///
58 | /// 使用SQL语句获取指定实体
59 | ///
60 | /// 返回实体类型
61 | /// DB 连接字符串配置节点名
62 | /// SQL语句
63 | /// 实体
64 | public virtual TAny QueryFirst(string connNameOrConnStr, string sql)
65 | {
66 | using (var connection = OpenConnection(connNameOrConnStr))
67 | {
68 | return connection.QueryFirstOrDefault(sql);
69 | }
70 | }
71 |
72 | ///
73 | /// 使用SQL语句获取指定实体
74 | ///
75 | /// 返回实体类型
76 | /// DB 连接字符串配置节点名
77 | /// SQL语句
78 | /// SQL参数
79 | /// 实体
80 | public virtual TAny QueryFirst(string connNameOrConnStr, string sql, object parameters)
81 | {
82 | using (var connection = OpenConnection(connNameOrConnStr))
83 | {
84 | return connection.QueryFirstOrDefault(sql, parameters);
85 | }
86 | }
87 |
88 | ///
89 | /// 使用SQL语句获取指定实体
90 | ///
91 | /// 返回实体类型
92 | /// DB 连接字符串配置节点名
93 | /// SQL语句
94 | /// SQL参数
95 | /// SQL语句命令类型
96 | /// 实体
97 | public virtual TAny QueryFirst(string connNameOrConnStr, string sql, object parameters, CommandType commandType)
98 | {
99 | using (var connection = OpenConnection(connNameOrConnStr))
100 | {
101 | return connection.QueryFirstOrDefault(sql, parameters, commandType: commandType);
102 | }
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.QueryFirst.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Linq;
5 | using System.Text;
6 | using Dapper;
7 |
8 | namespace DapperDal
9 | {
10 | public partial class DalBase where TEntity : class
11 | {
12 | ///
13 | /// 使用SQL语句获取实体
14 | ///
15 | /// SQL语句
16 | /// 实体
17 | public virtual TEntity QueryFirst(string sql)
18 | {
19 | using (var connection = OpenConnection())
20 | {
21 | return connection.QueryFirstOrDefault(sql);
22 | }
23 | }
24 |
25 | ///
26 | /// 使用SQL语句获取实体
27 | ///
28 | /// SQL语句
29 | /// SQL参数
30 | /// 实体
31 | public virtual TEntity QueryFirst(string sql, object parameters)
32 | {
33 | using (var connection = OpenConnection())
34 | {
35 | return connection.QueryFirstOrDefault(sql, parameters);
36 | }
37 | }
38 |
39 | ///
40 | /// 使用SQL语句获取实体
41 | ///
42 | /// SQL语句
43 | /// SQL参数
44 | /// SQL语句命令类型
45 | /// 实体
46 | public virtual TEntity QueryFirst(string sql, object parameters, CommandType commandType)
47 | {
48 | using (var connection = OpenConnection())
49 | {
50 | return connection.QueryFirstOrDefault(sql, parameters, commandType: commandType);
51 | }
52 | }
53 |
54 | ///
55 | /// 使用SQL语句获取指定实体
56 | ///
57 | /// 返回实体类型
58 | /// SQL语句
59 | /// 实体
60 | public virtual TAny QueryFirst(string sql)
61 | {
62 | using (var connection = OpenConnection())
63 | {
64 | return connection.QueryFirstOrDefault(sql);
65 | }
66 | }
67 |
68 | ///
69 | /// 使用SQL语句获取指定实体
70 | ///
71 | /// 返回实体类型
72 | /// SQL语句
73 | /// SQL参数
74 | /// 实体
75 | public virtual TAny QueryFirst(string sql, object parameters)
76 | {
77 | using (var connection = OpenConnection())
78 | {
79 | return connection.QueryFirstOrDefault(sql, parameters);
80 | }
81 | }
82 |
83 | ///
84 | /// 使用SQL语句获取指定实体
85 | ///
86 | /// 返回实体类型
87 | /// SQL语句
88 | /// SQL参数
89 | /// SQL语句命令类型
90 | /// 实体
91 | public virtual TAny QueryFirst(string sql, object parameters, CommandType commandType)
92 | {
93 | using (var connection = OpenConnection())
94 | {
95 | return connection.QueryFirstOrDefault(sql, parameters, commandType: commandType);
96 | }
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.SoftDelete.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 | using System.Text;
6 |
7 | namespace DapperDal
8 | {
9 | public partial class DalBase where TEntity : class
10 | {
11 | ///
12 | /// 逻辑删除指定实体
13 | ///
14 | /// 实体
15 | /// 逻辑删除属性名及更新值,默认 IsActive=0
16 | /// 逻辑删除结果
17 | public virtual bool SoftDelete(TEntity entity, object props = null)
18 | {
19 | return SwitchActive(entity, false, props);
20 | }
21 |
22 | ///
23 | /// 根据实体主键ID逻辑删除指定实体
24 | ///
25 | /// 实体主键ID
26 | /// 逻辑删除属性名及更新值,默认 IsActive=0
27 | /// 逻辑删除结果
28 | public virtual bool SoftDelete(TPrimaryKey id, object props = null)
29 | {
30 | return SwitchActive(id, false, props);
31 | }
32 |
33 | ///
34 | /// 根据条件逻辑删除实体
35 | ///
36 | /// 删除条件
37 | /// 逻辑删除属性名及更新值,默认 IsActive=0
38 | /// 逻辑删除结果
39 | public virtual bool SoftDelete(object predicate, object props = null)
40 | {
41 | return SwitchActive(predicate, false, props);
42 | }
43 |
44 | ///
45 | /// 根据条件逻辑删除实体
46 | ///
47 | /// 删除条件
48 | /// 逻辑删除属性名及更新值,默认 IsActive=0 }
49 | /// 逻辑删除结果
50 | public virtual bool SoftDelete(Expression> predicate, object props = null)
51 | {
52 | return SwitchActive(predicate, false, props);
53 | }
54 |
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.SwitchActive.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq.Expressions;
3 | using DapperDal.Expressions;
4 | using DapperDal.Predicate;
5 |
6 | namespace DapperDal
7 | {
8 | public partial class DalBase where TEntity : class
9 | {
10 | ///
11 | /// 逻辑删除或激活指定实体
12 | ///
13 | /// 实体
14 | /// 是否激活,true:激活,false:逻辑删除
15 | /// 逻辑删除属性名及更新值,默认:IsActive=0
16 | /// 激活属性名及更新值,默认:IsActive=1
17 | /// 更新结果
18 | public virtual bool SwitchActive(TEntity entity, bool isActive,
19 | object softDeleteProps = null, object softActiveProps = null)
20 | {
21 | if (isActive)
22 | {
23 | if (softActiveProps == null && Options.SoftActivePropsFactory != null)
24 | {
25 | softActiveProps = Options.SoftActivePropsFactory();
26 | }
27 |
28 | return Update(entity, softActiveProps);
29 | }
30 | else
31 | {
32 | if (softDeleteProps == null && Options.SoftDeletePropsFactory != null)
33 | {
34 | softDeleteProps = Options.SoftDeletePropsFactory();
35 | }
36 |
37 | return Update(entity, softDeleteProps);
38 | }
39 | }
40 |
41 | ///
42 | /// 根据实体主键ID逻辑删除或激活指定实体
43 | ///
44 | /// 实体主键ID
45 | /// 是否激活,true:激活,false:逻辑删除
46 | /// 逻辑删除属性名及更新值,默认:IsActive=0
47 | /// 激活属性名及更新值,默认:IsActive=1
48 | /// 更新结果
49 | public virtual bool SwitchActive(TPrimaryKey id, bool isActive,
50 | object softDeleteProps = null, object softActiveProps = null)
51 | {
52 | IPredicate predicate = Configuration.DalImplementor.GetIdPredicate(id);
53 |
54 | if (isActive)
55 | {
56 | if (softActiveProps == null && Options.SoftActivePropsFactory != null)
57 | {
58 | softActiveProps = Options.SoftActivePropsFactory();
59 | }
60 |
61 | return Update(softActiveProps, predicate);
62 | }
63 | else
64 | {
65 | if (softDeleteProps == null && Options.SoftDeletePropsFactory != null)
66 | {
67 | softDeleteProps = Options.SoftDeletePropsFactory();
68 | }
69 |
70 | return Update(softDeleteProps, predicate);
71 | }
72 | }
73 |
74 | ///
75 | /// 根据条件逻辑删除或激活实体
76 | ///
77 | /// 删除条件
78 | /// 是否激活,true:激活,false:逻辑删除
79 | /// 逻辑删除属性名及更新值,默认:IsActive=0
80 | /// 激活属性名及更新值,默认:IsActive=1
81 | /// 更新结果
82 | public virtual bool SwitchActive(object predicate, bool isActive,
83 | object softDeleteProps = null, object softActiveProps = null)
84 | {
85 | if (isActive)
86 | {
87 | if (softActiveProps == null && Options.SoftActivePropsFactory != null)
88 | {
89 | softActiveProps = Options.SoftActivePropsFactory();
90 | }
91 |
92 | return Update(softActiveProps, predicate);
93 | }
94 | else
95 | {
96 | if (softDeleteProps == null && Options.SoftDeletePropsFactory != null)
97 | {
98 | softDeleteProps = Options.SoftDeletePropsFactory();
99 | }
100 |
101 | return Update(softDeleteProps, predicate);
102 | }
103 | }
104 |
105 | ///
106 | /// 根据条件逻辑删除或激活实体
107 | ///
108 | /// 删除条件
109 | /// 是否激活,true:激活,false:逻辑删除
110 | /// 逻辑删除属性名及更新值,默认:IsActive=0
111 | /// 激活属性名及更新值,默认:IsActive=1
112 | /// 更新结果
113 | public virtual bool SwitchActive(Expression> predicate, bool isActive,
114 | object softDeleteProps = null, object softActiveProps = null)
115 | {
116 | if (isActive)
117 | {
118 | if (softActiveProps == null && Options.SoftActivePropsFactory != null)
119 | {
120 | softActiveProps = Options.SoftActivePropsFactory();
121 | }
122 |
123 | var predicateGp = predicate.ToPredicateGroup();
124 | return Update(softActiveProps, predicateGp);
125 | }
126 | else
127 | {
128 | if (softDeleteProps == null && Options.SoftDeletePropsFactory != null)
129 | {
130 | softDeleteProps = Options.SoftDeletePropsFactory();
131 | }
132 |
133 | var predicateGp = predicate.ToPredicateGroup();
134 | return Update(softDeleteProps, predicateGp);
135 | }
136 | }
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.Update.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 | using DapperDal.Expressions;
6 | using DapperDal.Predicate;
7 |
8 | namespace DapperDal
9 | {
10 | public partial class DalBase where TEntity : class
11 | {
12 | ///
13 | /// 更新指定实体
14 | ///
15 | /// 实体
16 | /// 更新结果
17 | public virtual bool Update(TEntity entity)
18 | {
19 | using (var connection = OpenConnection())
20 | {
21 | return Configuration.DalImplementor.Update(
22 | connection: connection,
23 | entity: entity,
24 | transaction: null,
25 | commandTimeout: null);
26 | }
27 | }
28 |
29 | ///
30 | /// 更新指定实体指定属性
31 | ///
32 | /// 实体
33 | /// 要更新的属性名列表
34 | /// 更新结果
35 | public virtual bool Update(TEntity entity, IEnumerable props)
36 | {
37 | using (var connection = OpenConnection())
38 | {
39 | return Configuration.DalImplementor.Update(
40 | connection: connection,
41 | entity: entity,
42 | props: props.ToList(),
43 | transaction: null,
44 | commandTimeout: null);
45 | }
46 | }
47 |
48 | ///
49 | /// 更新指定实体指定属性
50 | ///
51 | /// 实体
52 | /// 要更新的属性名列表,以匿名对象提供
53 | /// 更新结果
54 | public virtual bool Update(TEntity entity, object props)
55 | {
56 | using (var connection = OpenConnection())
57 | {
58 | return Configuration.DalImplementor.Update(
59 | connection: connection,
60 | entity: entity,
61 | props: props,
62 | transaction: null,
63 | commandTimeout: null);
64 | }
65 | }
66 |
67 | ///
68 | /// 更新指定实体指定属性
69 | ///
70 | /// 实体主键ID
71 | /// 更新属性名
72 | /// 更新结果
73 | public virtual bool Update(TPrimaryKey id, object props)
74 | {
75 | using (var connection = OpenConnection())
76 | {
77 | IPredicate predicate = Configuration.DalImplementor.GetIdPredicate(id);
78 |
79 | return Configuration.DalImplementor.Update(
80 | connection: connection,
81 | props: props,
82 | predicate: predicate,
83 | transaction: null,
84 | commandTimeout: null);
85 | }
86 | }
87 |
88 | ///
89 | /// 根据指定指定主键ID更新实体指定属性
90 | /// (条件使用实体主键ID)
91 | ///
92 | /// 更新实体,包含主键ID、更新属性及值
93 | /// 更新结果
94 | public virtual bool Update(object keyAndProps)
95 | {
96 | using (var connection = OpenConnection())
97 | {
98 | return Configuration.DalImplementor.Update(
99 | connection: connection,
100 | keyAndProps: keyAndProps,
101 | transaction: null,
102 | commandTimeout: null);
103 | }
104 | }
105 |
106 | ///
107 | /// 根据指定更新条件更新实体指定属性
108 | /// (条件使用谓词或匿名对象)
109 | ///
110 | /// 更新属性及值
111 | /// 更新条件,使用谓词或匿名对象
112 | /// 更新结果
113 | public virtual bool Update(object props, object predicate)
114 | {
115 | using (var connection = OpenConnection())
116 | {
117 | return Configuration.DalImplementor.Update(
118 | connection: connection,
119 | props: props,
120 | predicate: predicate,
121 | transaction: null,
122 | commandTimeout: null);
123 | }
124 | }
125 |
126 | ///
127 | /// 根据指定更新条件更新实体指定属性
128 | /// (条件使用表达式)
129 | ///
130 | /// 更新属性及值
131 | /// 更新条件,使用表达式
132 | /// 更新结果
133 | public virtual bool Update(object props, Expression> predicate)
134 | {
135 | using (var connection = OpenConnection())
136 | {
137 | var predicateGp = predicate.ToPredicateGroup();
138 |
139 | return Configuration.DalImplementor.Update(
140 | connection: connection,
141 | props: props,
142 | predicate: predicateGp,
143 | transaction: null,
144 | commandTimeout: null);
145 | }
146 | }
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/src/DapperDal/DalBaseOfTEntity.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arbing/DapperDal/bdb0beb99f3479e385bbad9970bbc4dda18ab925/src/DapperDal/DalBaseOfTEntity.cs
--------------------------------------------------------------------------------
/src/DapperDal/DalConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Concurrent;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Reflection;
6 | using DapperDal.Implementor;
7 | using DapperDal.Mapper;
8 | using DapperDal.Sql;
9 |
10 | namespace DapperDal
11 | {
12 | ///
13 | /// 数据访问配置接口
14 | ///
15 | public interface IDalConfiguration
16 | {
17 | ///
18 | /// 默认实体映射类型
19 | ///
20 | Type DefaultMapper { get; set; }
21 |
22 | ///
23 | /// 实体映射类型检索程序集
24 | ///
25 | IList MappingAssemblies { get; set; }
26 |
27 | ///
28 | /// SQL方言实例
29 | ///
30 | ISqlDialect Dialect { get; set; }
31 |
32 | ///
33 | /// 数据访问实现实例
34 | ///
35 | IDalImplementor DalImplementor { get; set; }
36 |
37 | ///
38 | /// 生成SQL时,是否添加 WITH (NOLOCK)
39 | ///
40 | bool Nolock { get; set; }
41 |
42 | ///
43 | /// SQL输出方法
44 | ///
45 | Action OutputSql { get; set; }
46 |
47 | ///
48 | /// 实体集合返回前是否要缓冲(ToList)
49 | ///
50 | bool Buffered { get; set; }
51 |
52 | ///
53 | /// 设置实体映射类型检索程序集
54 | ///
55 | /// 实体映射类型检索程序集
56 | void SetMappingAssemblies(IList assemblies);
57 |
58 | ///
59 | /// 获取实体映射类型
60 | ///
61 | /// 实体类型
62 | /// 实体映射类型
63 | IClassMapper GetMap(Type entityType);
64 |
65 | ///
66 | /// 获取实体映射类型
67 | ///
68 | /// 实体类型
69 | /// 实体映射类型
70 | IClassMapper GetMap() where T : class;
71 |
72 | ///
73 | /// 清空实体映射类型缓存
74 | ///
75 | void ClearCache();
76 |
77 | ///
78 | /// 获取新的GUID
79 | ///
80 | /// 新的GUID
81 | Guid GetNextGuid();
82 | }
83 |
84 | ///
85 | /// 数据访问配置类
86 | ///
87 | public class DalConfiguration : IDalConfiguration
88 | {
89 | private readonly ConcurrentDictionary _classMaps = new ConcurrentDictionary();
90 |
91 | static DalConfiguration()
92 | {
93 | Default = new DalConfiguration();
94 | }
95 |
96 | ///
97 | /// 初始化数据访问配置
98 | ///
99 | public DalConfiguration()
100 | : this(typeof(AutoClassMapper<>), new List(), new SqlServerDialect())
101 | {
102 | }
103 |
104 |
105 | ///
106 | /// 初始化数据访问配置
107 | ///
108 | /// 默认实体映射类型
109 | /// 实体映射类型检索程序集
110 | /// SQL方言实例
111 | public DalConfiguration(Type defaultMapper, IList mappingAssemblies, ISqlDialect sqlDialect)
112 | {
113 | DefaultMapper = defaultMapper;
114 | MappingAssemblies = mappingAssemblies ?? new List();
115 | Dialect = sqlDialect;
116 | DalImplementor = new DalImplementor(new SqlGeneratorImpl(this));
117 | }
118 |
119 | ///
120 | /// 全局默认配置
121 | ///
122 | public static IDalConfiguration Default { get; }
123 |
124 | ///
125 | public Type DefaultMapper { get; set; }
126 |
127 | ///
128 | public IList MappingAssemblies { get; set; }
129 |
130 | ///
131 | public ISqlDialect Dialect { get; set; }
132 |
133 | ///
134 | public IDalImplementor DalImplementor { get; set; }
135 |
136 | ///
137 | /// 生成SQL时,是否添加 WITH (NOLOCK)
138 | ///
139 | public bool Nolock { get; set; }
140 |
141 | ///
142 | /// SQL输出方法
143 | ///
144 | public Action OutputSql { get; set; }
145 |
146 | ///
147 | /// 实体集合返回前是否要缓冲(ToList)
148 | ///
149 | public bool Buffered { get; set; }
150 |
151 | ///
152 | public void SetMappingAssemblies(IList assemblies)
153 | {
154 | MappingAssemblies = assemblies ?? new List();
155 | ClearCache();
156 | DalImplementor = new DalImplementor(new SqlGeneratorImpl(this));
157 | }
158 |
159 | ///
160 | public IClassMapper GetMap(Type entityType)
161 | {
162 | IClassMapper map;
163 | if (!_classMaps.TryGetValue(entityType, out map))
164 | {
165 | Type mapType = GetMapType(entityType);
166 | if (mapType == null)
167 | {
168 | mapType = DefaultMapper.MakeGenericType(entityType);
169 | }
170 |
171 | map = Activator.CreateInstance(mapType) as IClassMapper;
172 | _classMaps[entityType] = map;
173 | }
174 |
175 | return map;
176 | }
177 |
178 | ///
179 | public IClassMapper GetMap() where T : class
180 | {
181 | return GetMap(typeof(T));
182 | }
183 |
184 | ///
185 | public void ClearCache()
186 | {
187 | _classMaps.Clear();
188 | }
189 |
190 | ///
191 | public Guid GetNextGuid()
192 | {
193 | byte[] b = Guid.NewGuid().ToByteArray();
194 | DateTime dateTime = new DateTime(1900, 1, 1);
195 | DateTime now = DateTime.Now;
196 | TimeSpan timeSpan = new TimeSpan(now.Ticks - dateTime.Ticks);
197 | TimeSpan timeOfDay = now.TimeOfDay;
198 | byte[] bytes1 = BitConverter.GetBytes(timeSpan.Days);
199 | byte[] bytes2 = BitConverter.GetBytes((long)(timeOfDay.TotalMilliseconds / 3.333333));
200 | Array.Reverse(bytes1);
201 | Array.Reverse(bytes2);
202 | Array.Copy(bytes1, bytes1.Length - 2, b, b.Length - 6, 2);
203 | Array.Copy(bytes2, bytes2.Length - 4, b, b.Length - 4, 4);
204 | return new Guid(b);
205 | }
206 |
207 | private Type GetMapType(Type entityType)
208 | {
209 | Func getType = a =>
210 | {
211 | Type[] types = a.GetTypes();
212 | return (from type in types
213 | let interfaceType = type.GetInterface(typeof(IClassMapper<>).FullName)
214 | where
215 | interfaceType != null &&
216 | interfaceType.GetGenericArguments()[0] == entityType
217 | select type).SingleOrDefault();
218 | };
219 |
220 | Type result = getType(entityType.Assembly);
221 | if (result != null)
222 | {
223 | return result;
224 | }
225 |
226 | foreach (var mappingAssembly in MappingAssemblies)
227 | {
228 | result = getType(mappingAssembly);
229 | if (result != null)
230 | {
231 | return result;
232 | }
233 | }
234 |
235 | return getType(entityType.Assembly);
236 | }
237 | }
238 | }
--------------------------------------------------------------------------------
/src/DapperDal/DalOptions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DapperDal
4 | {
5 | ///
6 | /// 数据访问设置项
7 | ///
8 | public class DalOptions
9 | {
10 | ///
11 | /// 逻辑删除时更新属性和值的构造器
12 | ///
13 | public Func