├── .gitignore ├── EFCore.OpenEdge.sln ├── LICENSE ├── README.md ├── efcoreoe.snk └── src └── EFCore.OpenEdge ├── Design └── Internal │ ├── OpenEdgeAnnotationCodeGenerator.cs │ └── OpenEdgeDesignTimeServices.cs ├── EFCore.OpenEdge.csproj ├── Extensions ├── OpenEdgeDataReaderExtensions.cs ├── OpenEdgeDbContextOptionsBuilderExtensions.cs ├── OpenEdgeServiceCollectionExtensions.cs ├── OpenEdgeSharedTypeExtensions.cs └── OpenEdgeStringExtensions.cs ├── Infrastructure └── Internal │ └── OpenEdgeOptionsExtension.cs ├── Metadata └── Conventions │ └── Internal │ └── OpenEdgeRelationalConventionSetBuilder.cs ├── Properties └── AssemblyInfo.cs ├── Query ├── ExpressionTranslators │ └── Internal │ │ ├── OpenEdgeCompositeMemberTranslator.cs │ │ └── OpenEdgeCompositeMethodCallTranslator.cs ├── ExpressionVisitors │ └── Internal │ │ └── OpenEdgeParameterExtractingExpressionVisitor.cs ├── Internal │ ├── OpenEdgeQueryModelGenerator.cs │ └── OpenEdgeResultOperatorHandler.cs └── Sql │ └── Internal │ ├── OpenEdgeSqlGenerator.cs │ └── OpenEdgeSqlGeneratorFactory.cs ├── Scaffolding └── Internal │ ├── OpenEdgeCodeGenerator.cs │ └── OpenEdgeDatabaseModelFactory.cs ├── Storage ├── IOpenEdgeRelationalConnection.cs ├── Internal │ ├── IOpenEdgeSqlGenerationHelper.cs │ ├── Mapping │ │ ├── OpenEdgeBoolTypeMapping.cs │ │ └── OpenEdgeTypeMappingSource.cs │ └── OpenEdgeSqlGenerationHelper.cs └── OpenEdgeRelationalConnection.cs └── Update ├── IOpenEdgeUpdateSqlGenerator.cs ├── Internal └── OpenEdgeModificationCommandBatchFactory.cs ├── OpenEdgeSingularModificationCommandBatch.cs └── OpenEdgeUpdateSqlGenerator.cs /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /EFCore.OpenEdge.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.136 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.OpenEdge", "src\EFCore.OpenEdge\EFCore.OpenEdge.csproj", "{21A6CF0F-EBB8-48CA-A843-ECFF81F94E0D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {21A6CF0F-EBB8-48CA-A843-ECFF81F94E0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {21A6CF0F-EBB8-48CA-A843-ECFF81F94E0D}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {21A6CF0F-EBB8-48CA-A843-ECFF81F94E0D}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {21A6CF0F-EBB8-48CA-A843-ECFF81F94E0D}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {36C294ED-9ECE-42AA-8273-31E008749AF3} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Entity Framework Core provider for Progress OpenEdge 2 | 3 | [![Nuget](https://img.shields.io/nuget/v/EntityFrameworkCore.OpenEdge.svg)](https://www.nuget.org/packages/EntityFrameworkCore.OpenEdge) 4 | [![Nuget](https://img.shields.io/nuget/dt/EntityFrameworkCore.OpenEdge.svg)](https://www.nuget.org/packages/EntityFrameworkCore.OpenEdge) 5 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Falexwiese%2FEntityFrameworkCore.OpenEdge.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Falexwiese%2FEntityFrameworkCore.OpenEdge?ref=badge_shield) 6 | 7 | EntityFrameworkCore.OpenEdge is an Entity Framework Core provider that allows you to use Entity Framework Core with Progress OpenEdge. 8 | 9 | ## Usage 10 | 11 | ### DSN-less Connection 12 | 13 | public class MyDbContext : DbContext 14 | { 15 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 16 | { 17 | optionsBuilder.UseOpenEdge("Driver=Progress OpenEdge 11.7 Driver;HOST=localhost;port=10000;UID=;PWD=;DIL=1;Database="); 18 | } 19 | } 20 | 21 | ### Using a DSN 22 | 23 | Create an ODBC DSN for your Progress OpenEdge database. Pass the connection string to the `UseOpenEdge` extension method. 24 | 25 | public class MyDbContext : DbContext 26 | { 27 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 28 | { 29 | optionsBuilder.UseOpenEdge("dsn=MyDb;password=mypassword"); 30 | } 31 | } 32 | 33 | ## Scaffold/reverse engineer your model 34 | 35 | From the Nuget Package Manager Console run this command (replacing the connection string). 36 | 37 | Scaffold-DbContext "dsn=MyDb;password=mypassword" EntityFrameworkCore.OpenEdge -OutputDir Models 38 | 39 | 40 | ## What's working? 41 | 42 | - Basic Queries 43 | - Joins 44 | - Inserts 45 | - Updates 46 | - Deletes 47 | - Scaffolding 48 | 49 | ## Gotchas 50 | 51 | OpenEdge Databases are a bit different when it comes to primary keys. Ie. there aren’t any “real” primary keys. There are primary indexes but they do _not_ have to be unique which causes issues with EFCore (which the provider can’t circumvent). EFCore entity tracking requires all primary keys to be unique, otherwise the materialised entity objects will conflict. The only thing that is close to a primary key (if there is no unique, primary index available) in OpenEdge is the “rowid”. You can expose the rowid and use that as the primary key. 52 | 53 | Example: 54 | 55 | [Key] 56 | [Column("rowid")] 57 | public string Rowid { get; set; } 58 | 59 | Note that rowid is a special OpenEdge value that uniquely represents the record, this means you can add this to any OpenEdge entity and use it as a proper primary key. 60 | 61 | For a unique primary index that has multiple fields then you can do the following in OnModelCreating: 62 | 63 | modelBuilder.Entity().HasKey("TransactionId", "ClientId", "SecondaryId"); 64 | 65 | 66 | ## License 67 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Falexwiese%2FEntityFrameworkCore.OpenEdge.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Falexwiese%2FEntityFrameworkCore.OpenEdge?ref=badge_large) 68 | -------------------------------------------------------------------------------- /efcoreoe.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexwiese/EntityFrameworkCore.OpenEdge/b183b239993b93de759c9c364ab30f7a2dc6b617/efcoreoe.snk -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Design/Internal/OpenEdgeAnnotationCodeGenerator.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Design; 2 | 3 | namespace EntityFrameworkCore.OpenEdge.Design.Internal 4 | { 5 | public class OpenEdgeAnnotationCodeGenerator : AnnotationCodeGenerator 6 | { 7 | public OpenEdgeAnnotationCodeGenerator(AnnotationCodeGeneratorDependencies dependencies) : base(dependencies) 8 | { 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Design/Internal/OpenEdgeDesignTimeServices.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkCore.OpenEdge.Scaffolding.Internal; 2 | using EntityFrameworkCore.OpenEdge.Storage.Internal.Mapping; 3 | using Microsoft.EntityFrameworkCore.Design; 4 | using Microsoft.EntityFrameworkCore.Scaffolding; 5 | using Microsoft.EntityFrameworkCore.Storage; 6 | using Microsoft.Extensions.DependencyInjection; 7 | 8 | namespace EntityFrameworkCore.OpenEdge.Design.Internal 9 | { 10 | public class OpenEdgeDesignTimeServices : IDesignTimeServices 11 | { 12 | public void ConfigureDesignTimeServices(IServiceCollection serviceCollection) 13 | => serviceCollection 14 | .AddSingleton() 15 | .AddSingleton() 16 | .AddSingleton() 17 | .AddSingleton() 18 | ; 19 | } 20 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/EFCore.OpenEdge.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | EntityFrameworkCore.OpenEdge 6 | EntityFrameworkCore.OpenEdge 7 | 7.2 8 | 1.0.0 9 | true 10 | ../../efcoreoe.snk 11 | true 12 | Alex Wiese 13 | Entity Framework Core provider for Progress OpenEdge 14 | https://github.com/alexwiese/EntityFrameworkCore.OpenEdge 15 | https://github.com/alexwiese/EntityFrameworkCore.OpenEdge 16 | git 17 | openedge;progress;Entity Framework Core;entity-framework-core;ef;efcore;orm;sql 18 | 19 | 20 | 21 | true 22 | 23 | true 24 | 1.0.11 25 | Map missing types clob, blob, double, recid, don't insert rowid. 26 | 1.0.0.0 27 | MIT 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Extensions/OpenEdgeDataReaderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.Common; 3 | 4 | namespace EntityFrameworkCore.OpenEdge.Extensions 5 | { 6 | public static class OpenEdgeDataReaderExtensions 7 | { 8 | public static T GetValueOrDefault(this DbDataReader reader, string name) 9 | { 10 | var idx = reader.GetOrdinal(name); 11 | return reader.IsDBNull(idx) 12 | ? default 13 | : (T)GetValue(reader.GetValue(idx)); 14 | } 15 | 16 | public static T GetValueOrDefault(this DbDataRecord record, string name) 17 | { 18 | var idx = record.GetOrdinal(name); 19 | return record.IsDBNull(idx) 20 | ? default 21 | : (T)GetValue(record.GetValue(idx)); 22 | } 23 | 24 | private static object GetValue(object valueRecord) 25 | { 26 | switch (typeof(T).Name) 27 | { 28 | case nameof(Int32): 29 | return Convert.ToInt32(valueRecord); 30 | case nameof(Boolean): 31 | return Convert.ToBoolean(valueRecord); 32 | default: 33 | return valueRecord; 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Extensions/OpenEdgeDbContextOptionsBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EntityFrameworkCore.OpenEdge.Infrastructure.Internal; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Infrastructure; 5 | 6 | namespace Microsoft.EntityFrameworkCore 7 | { 8 | public static class OpenEdgeDbContextOptionsBuilderExtensions 9 | { 10 | public static DbContextOptionsBuilder UseOpenEdge( 11 | this DbContextOptionsBuilder optionsBuilder, 12 | string connectionString, 13 | Action optionsAction = null) 14 | { 15 | 16 | var extension = GetOrCreateExtension(optionsBuilder).WithConnectionString(connectionString); 17 | ((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(extension); 18 | 19 | optionsAction?.Invoke(optionsBuilder); 20 | 21 | return optionsBuilder; 22 | } 23 | 24 | public static DbContextOptionsBuilder UseOpenEdge( 25 | this DbContextOptionsBuilder optionsBuilder, 26 | string connectionString, 27 | Action optionsAction = null) 28 | where TContext : DbContext 29 | => (DbContextOptionsBuilder)UseOpenEdge( 30 | (DbContextOptionsBuilder)optionsBuilder, connectionString, optionsAction); 31 | 32 | private static OpenEdgeOptionsExtension GetOrCreateExtension(DbContextOptionsBuilder optionsBuilder) 33 | => optionsBuilder.Options.FindExtension() ?? new OpenEdgeOptionsExtension(); 34 | } 35 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Extensions/OpenEdgeServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkCore.OpenEdge.Infrastructure.Internal; 2 | using EntityFrameworkCore.OpenEdge.Metadata.Conventions.Internal; 3 | using EntityFrameworkCore.OpenEdge.Query.ExpressionTranslators.Internal; 4 | using EntityFrameworkCore.OpenEdge.Query.Internal; 5 | using EntityFrameworkCore.OpenEdge.Query.Sql.Internal; 6 | using EntityFrameworkCore.OpenEdge.Storage; 7 | using EntityFrameworkCore.OpenEdge.Storage.Internal; 8 | using EntityFrameworkCore.OpenEdge.Storage.Internal.Mapping; 9 | using EntityFrameworkCore.OpenEdge.Update; 10 | using EntityFrameworkCore.OpenEdge.Update.Internal; 11 | using Microsoft.EntityFrameworkCore.Infrastructure; 12 | using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal; 13 | using Microsoft.EntityFrameworkCore.Query; 14 | using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; 15 | using Microsoft.EntityFrameworkCore.Query.Internal; 16 | using Microsoft.EntityFrameworkCore.Query.Sql; 17 | using Microsoft.EntityFrameworkCore.Storage; 18 | using Microsoft.EntityFrameworkCore.Update; 19 | using Microsoft.EntityFrameworkCore.Update.Internal; 20 | using Microsoft.Extensions.DependencyInjection; 21 | 22 | namespace EntityFrameworkCore.OpenEdge.Extensions 23 | { 24 | public static class OpenEdgeServiceCollectionExtensions 25 | { 26 | public static IServiceCollection AddEntityFrameworkOpenEdge(this IServiceCollection serviceCollection) 27 | { 28 | var builder = new EntityFrameworkRelationalServicesBuilder(serviceCollection) 29 | .TryAdd>() 30 | .TryAdd() 31 | .TryAdd() 32 | .TryAdd() 33 | .TryAdd() 34 | .TryAdd() 35 | .TryAdd() 36 | .TryAdd(p => p.GetService()) 37 | .TryAdd() 38 | .TryAdd() 39 | 40 | .TryAdd() 41 | 42 | .TryAdd() 43 | .TryAdd() 44 | .TryAdd() 45 | 46 | .TryAddProviderSpecificServices(b => b 47 | .TryAddScoped() 48 | .TryAddScoped()); ; 49 | 50 | builder.TryAddCoreServices(); 51 | return serviceCollection; 52 | } 53 | 54 | } 55 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Extensions/OpenEdgeSharedTypeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace EntityFrameworkCore.OpenEdge.Extensions 5 | { 6 | public static class OpenEdgeSharedTypeExtensions 7 | { 8 | public static Type UnwrapNullableType(this Type type) => Nullable.GetUnderlyingType(type) ?? type; 9 | 10 | public static bool IsInteger(this Type type) 11 | { 12 | type = type.UnwrapNullableType(); 13 | 14 | return type == typeof(int) 15 | || type == typeof(long) 16 | || type == typeof(short) 17 | || type == typeof(byte) 18 | || type == typeof(uint) 19 | || type == typeof(ulong) 20 | || type == typeof(ushort) 21 | || type == typeof(sbyte) 22 | || type == typeof(char); 23 | } 24 | 25 | public static bool IsNullableType(this Type type) 26 | { 27 | var typeInfo = type.GetTypeInfo(); 28 | 29 | return !typeInfo.IsValueType 30 | || typeInfo.IsGenericType 31 | && typeInfo.GetGenericTypeDefinition() == typeof(Nullable<>); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Extensions/OpenEdgeStringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace EntityFrameworkCore.OpenEdge.Extensions 6 | { 7 | public static class OpenEdgeStringExtensions 8 | { 9 | public static StringBuilder AppendJoin( 10 | this StringBuilder stringBuilder, 11 | IEnumerable values, 12 | TParam param, 13 | Action joinAction, 14 | string separator = ", ") 15 | { 16 | var appended = false; 17 | 18 | foreach (var value in values) 19 | { 20 | joinAction(stringBuilder, value, param); 21 | stringBuilder.Append(separator); 22 | appended = true; 23 | } 24 | 25 | if (appended) 26 | { 27 | stringBuilder.Length -= separator.Length; 28 | } 29 | 30 | return stringBuilder; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Infrastructure/Internal/OpenEdgeOptionsExtension.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkCore.OpenEdge.Extensions; 2 | using Microsoft.EntityFrameworkCore.Infrastructure; 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace EntityFrameworkCore.OpenEdge.Infrastructure.Internal 6 | { 7 | public class OpenEdgeOptionsExtension : RelationalOptionsExtension 8 | { 9 | protected override RelationalOptionsExtension Clone() 10 | { 11 | return new OpenEdgeOptionsExtension(); 12 | } 13 | 14 | public override bool ApplyServices(IServiceCollection services) 15 | { 16 | services.AddEntityFrameworkOpenEdge(); 17 | return true; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Metadata/Conventions/Internal/OpenEdgeRelationalConventionSetBuilder.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal; 2 | 3 | namespace EntityFrameworkCore.OpenEdge.Metadata.Conventions.Internal 4 | { 5 | public class OpenEdgeRelationalConventionSetBuilder : RelationalConventionSetBuilder 6 | { 7 | public OpenEdgeRelationalConventionSetBuilder(RelationalConventionSetBuilderDependencies dependencies) : base(dependencies) 8 | { 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Design; 2 | 3 | [assembly: DesignTimeProviderServices("EntityFrameworkCore.OpenEdge.Design.Internal.OpenEdgeDesignTimeServices")] 4 | -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Query/ExpressionTranslators/Internal/OpenEdgeCompositeMemberTranslator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; 5 | 6 | namespace EntityFrameworkCore.OpenEdge.Query.ExpressionTranslators.Internal 7 | { 8 | public class OpenEdgeCompositeMemberTranslator : RelationalCompositeMemberTranslator 9 | { 10 | private static readonly List _translatorsMethods 11 | = OpenEdgeCompositeMethodCallTranslator.GetTranslatorMethods().ToList(); 12 | 13 | public OpenEdgeCompositeMemberTranslator(RelationalCompositeMemberTranslatorDependencies dependencies) 14 | : base(dependencies) 15 | => AddTranslators(_translatorsMethods.Select(type => (IMemberTranslator)Activator.CreateInstance(type))); 16 | } 17 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Query/ExpressionTranslators/Internal/OpenEdgeCompositeMethodCallTranslator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; 6 | 7 | namespace EntityFrameworkCore.OpenEdge.Query.ExpressionTranslators.Internal 8 | { 9 | public class OpenEdgeCompositeMethodCallTranslator : RelationalCompositeMethodCallTranslator 10 | { 11 | private static readonly List _translatorsMethods 12 | = GetTranslatorMethods().ToList(); 13 | 14 | public OpenEdgeCompositeMethodCallTranslator(RelationalCompositeMethodCallTranslatorDependencies dependencies) 15 | : base(dependencies) 16 | => AddTranslators(_translatorsMethods.Select(type => (IMethodCallTranslator)Activator.CreateInstance(type))); 17 | 18 | public static IEnumerable GetTranslatorMethods() 19 | => Assembly 20 | .GetExecutingAssembly() 21 | .GetTypes().Where(t => 22 | t.GetInterfaces().Any(i => i == typeof(TInteface)) 23 | && t.GetConstructors().Any(c => c.GetParameters().Length == 0)); 24 | } 25 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Query/ExpressionVisitors/Internal/OpenEdgeParameterExtractingExpressionVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Linq.Expressions; 3 | using System.Reflection; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Diagnostics; 6 | using Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal; 7 | using Microsoft.EntityFrameworkCore.Query.Internal; 8 | using Remotion.Linq.Parsing.ExpressionVisitors.TreeEvaluation; 9 | 10 | namespace EntityFrameworkCore.OpenEdge.Query.ExpressionVisitors.Internal 11 | { 12 | public class OpenEdgeParameterExtractingExpressionVisitor : ParameterExtractingExpressionVisitor 13 | { 14 | public OpenEdgeParameterExtractingExpressionVisitor(IEvaluatableExpressionFilter evaluatableExpressionFilter, 15 | IParameterValues parameterValues, 16 | IDiagnosticsLogger logger, 17 | DbContext context, 18 | bool parameterize, bool 19 | generateContextAccessors = false) 20 | : base(evaluatableExpressionFilter, parameterValues, logger, context, parameterize, generateContextAccessors) 21 | { 22 | } 23 | 24 | protected Expression VisitNewMember(MemberExpression memberExpression) 25 | { 26 | if (memberExpression.Expression is ConstantExpression constant 27 | && constant.Value != null) 28 | { 29 | switch (memberExpression.Member.MemberType) 30 | { 31 | case MemberTypes.Field: 32 | return Expression.Constant(constant.Value.GetType().GetField(memberExpression.Member.Name).GetValue(constant.Value)); 33 | 34 | case MemberTypes.Property: 35 | var propertyInfo = constant.Value.GetType().GetProperty(memberExpression.Member.Name); 36 | if (propertyInfo == null) 37 | { 38 | break; 39 | } 40 | 41 | return Expression.Constant(propertyInfo.GetValue(constant.Value)); 42 | } 43 | } 44 | 45 | return base.VisitMember(memberExpression); 46 | } 47 | 48 | protected override Expression VisitNew(NewExpression node) 49 | { 50 | var memberArguments = node.Arguments 51 | .Select(m => m is MemberExpression mem ? VisitNewMember(mem) : Visit(m)) 52 | .ToList(); 53 | 54 | var newNode = node.Update(memberArguments); 55 | 56 | return newNode; 57 | } 58 | 59 | protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) 60 | { 61 | if (methodCallExpression.Method.Name == "Take") 62 | { 63 | return methodCallExpression; 64 | } 65 | 66 | if (methodCallExpression.Method.Name == "Skip") 67 | { 68 | return methodCallExpression; 69 | } 70 | 71 | return base.VisitMethodCall(methodCallExpression); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryModelGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | using EntityFrameworkCore.OpenEdge.Query.ExpressionVisitors.Internal; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Diagnostics; 6 | using Microsoft.EntityFrameworkCore.Internal; 7 | using Microsoft.EntityFrameworkCore.Query.Internal; 8 | using Remotion.Linq.Parsing.ExpressionVisitors.TreeEvaluation; 9 | 10 | namespace EntityFrameworkCore.OpenEdge.Query.Internal 11 | { 12 | public class OpenEdgeQueryModelGenerator : QueryModelGenerator 13 | { 14 | private readonly IEvaluatableExpressionFilter _evaluatableExpressionFilter; 15 | private readonly ICurrentDbContext _currentDbContext; 16 | 17 | public OpenEdgeQueryModelGenerator(INodeTypeProviderFactory nodeTypeProviderFactory, 18 | IEvaluatableExpressionFilter evaluatableExpressionFilter, 19 | ICurrentDbContext currentDbContext) 20 | : base(nodeTypeProviderFactory, evaluatableExpressionFilter, currentDbContext) 21 | { 22 | _evaluatableExpressionFilter = evaluatableExpressionFilter; 23 | _currentDbContext = currentDbContext; 24 | } 25 | 26 | public override Expression ExtractParameters(IDiagnosticsLogger logger, Expression query, IParameterValues parameterValues, 27 | bool parameterize = true, bool generateContextAccessors = false) 28 | { 29 | return new OpenEdgeParameterExtractingExpressionVisitor(_evaluatableExpressionFilter, parameterValues, logger, 30 | _currentDbContext.Context, 31 | parameterize, generateContextAccessors).ExtractParameters(query); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Query/Internal/OpenEdgeResultOperatorHandler.cs: -------------------------------------------------------------------------------- 1 | using JetBrains.Annotations; 2 | using Microsoft.EntityFrameworkCore.Metadata; 3 | using Microsoft.EntityFrameworkCore.Query; 4 | using Microsoft.EntityFrameworkCore.Query.Expressions; 5 | using Microsoft.EntityFrameworkCore.Query.ExpressionVisitors; 6 | using Microsoft.EntityFrameworkCore.Query.Internal; 7 | 8 | namespace EntityFrameworkCore.OpenEdge.Query.Internal 9 | { 10 | public class OpenEdgeResultOperatorHandler : RelationalResultOperatorHandler 11 | { 12 | public OpenEdgeResultOperatorHandler(IModel model, 13 | ISqlTranslatingExpressionVisitorFactory sqlTranslatingExpressionVisitorFactory, 14 | ISelectExpressionFactory selectExpressionFactory, 15 | IResultOperatorHandler resultOperatorHandler) 16 | : base(model, sqlTranslatingExpressionVisitorFactory, 17 | selectExpressionFactory, resultOperatorHandler) 18 | { 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Query/Sql/Internal/OpenEdgeSqlGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Linq.Expressions; 4 | using EntityFrameworkCore.OpenEdge.Extensions; 5 | using Microsoft.EntityFrameworkCore.Query.Expressions; 6 | using Microsoft.EntityFrameworkCore.Query.Sql; 7 | using Microsoft.EntityFrameworkCore.Storage; 8 | 9 | namespace EntityFrameworkCore.OpenEdge.Query.Sql.Internal 10 | { 11 | public class OpenEdgeSqlGenerator : DefaultQuerySqlGenerator 12 | { 13 | private bool _existsConditional; 14 | 15 | public OpenEdgeSqlGenerator(QuerySqlGeneratorDependencies dependencies, SelectExpression selectExpression) 16 | : base(dependencies, selectExpression) 17 | { 18 | } 19 | 20 | protected override Expression VisitParameter(ParameterExpression parameterExpression) 21 | { 22 | var parameterName = SqlGenerator.GenerateParameterName(parameterExpression.Name); 23 | 24 | if (Sql.ParameterBuilder.Parameters 25 | .All(p => p.InvariantName != parameterExpression.Name)) 26 | { 27 | var typeMapping 28 | = Dependencies.TypeMappingSource.GetMapping(parameterExpression.Type); 29 | 30 | Sql.AddParameter( 31 | parameterExpression.Name, 32 | parameterName, 33 | typeMapping, 34 | parameterExpression.Type.IsNullableType()); 35 | } 36 | 37 | // Named parameters not supported in the command text 38 | // Need to use '?' instead 39 | Sql.Append("?"); 40 | 41 | return parameterExpression; 42 | } 43 | 44 | protected override Expression VisitConditional(ConditionalExpression conditionalExpression) 45 | { 46 | var visitConditional = base.VisitConditional(conditionalExpression); 47 | 48 | // OpenEdge requires that SELECT statements always include a table, 49 | // so we SELECT from the _File metaschema table that always exists, 50 | // selecting a single row that we know will always exist; the metaschema 51 | // record for the _File metaschema table itself. 52 | if (_existsConditional) 53 | Sql.Append(@" FROM pub.""_File"" f WHERE f.""_File-Name"" = '_File'"); 54 | 55 | _existsConditional = false; 56 | 57 | return visitConditional; 58 | } 59 | 60 | public override Expression VisitExists(ExistsExpression existsExpression) 61 | { 62 | // OpenEdge does not support WHEN EXISTS, only WHERE EXISTS 63 | // We need to SELECT 1 using WHERE EXISTS, then compare 64 | // the result to 1 to satisfy the conditional. 65 | 66 | // OpenEdge requires that SELECT statements always include a table, 67 | // so we SELECT from the _File metaschema table that always exists, 68 | // selecting a single row that we know will always exist; the metaschema 69 | // record for the _File metaschema table itself. 70 | Sql.AppendLine(@"(SELECT 1 FROM pub.""_File"" f WHERE f.""_File-Name"" = '_File' AND EXISTS ("); 71 | 72 | using (Sql.Indent()) 73 | { 74 | Visit(existsExpression.Subquery); 75 | } 76 | 77 | Sql.Append(")) = 1"); 78 | 79 | _existsConditional = true; 80 | 81 | return existsExpression; 82 | } 83 | 84 | protected override void GenerateTop(SelectExpression selectExpression) 85 | { 86 | if (selectExpression.Limit != null 87 | && selectExpression.Offset == null) 88 | { 89 | // OpenEdge doesn't allow braces around the limit 90 | Sql.Append("TOP "); 91 | 92 | Visit(selectExpression.Limit); 93 | 94 | Sql.Append(" "); 95 | } 96 | } 97 | 98 | protected override Expression VisitConstant(ConstantExpression constantExpression) 99 | { 100 | if ((constantExpression.Type == typeof(DateTime) || constantExpression.Type == typeof(DateTime?)) 101 | && constantExpression.Value != null) 102 | { 103 | var dateTime = (DateTime)constantExpression.Value; 104 | Sql.Append($"{{ ts '{dateTime:yyyy-MM-dd HH:mm:ss}' }}"); 105 | } 106 | else 107 | base.VisitConstant(constantExpression); 108 | 109 | return constantExpression; 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Query/Sql/Internal/OpenEdgeSqlGeneratorFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Query.Expressions; 2 | using Microsoft.EntityFrameworkCore.Query.Sql; 3 | 4 | namespace EntityFrameworkCore.OpenEdge.Query.Sql.Internal 5 | { 6 | public class OpenEdgeSqlGeneratorFactory : QuerySqlGeneratorFactoryBase 7 | { 8 | public OpenEdgeSqlGeneratorFactory( 9 | QuerySqlGeneratorDependencies dependencies) 10 | : base(dependencies) 11 | { 12 | } 13 | 14 | public override IQuerySqlGenerator CreateDefault(SelectExpression selectExpression) 15 | => new OpenEdgeSqlGenerator(Dependencies, selectExpression); 16 | } 17 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Scaffolding/Internal/OpenEdgeCodeGenerator.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkCore.OpenEdge.Extensions; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Design; 4 | using Microsoft.EntityFrameworkCore.Scaffolding; 5 | 6 | namespace EntityFrameworkCore.OpenEdge.Scaffolding.Internal 7 | { 8 | public class OpenEdgeCodeGenerator : ProviderCodeGenerator 9 | { 10 | public OpenEdgeCodeGenerator(ProviderCodeGeneratorDependencies dependencies) 11 | : base(dependencies) 12 | { 13 | } 14 | 15 | public override MethodCallCodeFragment GenerateUseProvider(string connectionString) 16 | { 17 | return new MethodCallCodeFragment(nameof(OpenEdgeDbContextOptionsBuilderExtensions.UseOpenEdge), connectionString); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Scaffolding/Internal/OpenEdgeDatabaseModelFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Data.Common; 5 | using System.Data.Odbc; 6 | using System.Linq; 7 | using System.Text; 8 | using EntityFrameworkCore.OpenEdge.Extensions; 9 | using Microsoft.EntityFrameworkCore; 10 | using Microsoft.EntityFrameworkCore.Diagnostics; 11 | using Microsoft.EntityFrameworkCore.Migrations; 12 | using Microsoft.EntityFrameworkCore.Scaffolding; 13 | using Microsoft.EntityFrameworkCore.Scaffolding.Metadata; 14 | 15 | namespace EntityFrameworkCore.OpenEdge.Scaffolding.Internal 16 | { 17 | public class OpenEdgeDatabaseModelFactory : IDatabaseModelFactory 18 | { 19 | protected internal const string DatabaseModelDefaultSchema = "pub"; 20 | private readonly IDiagnosticsLogger _logger; 21 | 22 | public OpenEdgeDatabaseModelFactory(IDiagnosticsLogger logger) 23 | { 24 | _logger = logger; 25 | } 26 | 27 | public DatabaseModel Create(string connectionString, IEnumerable tables, IEnumerable schemas) 28 | { 29 | using (var connection = new OdbcConnection(connectionString)) 30 | { 31 | return Create(connection, tables, schemas); 32 | } 33 | } 34 | 35 | public DatabaseModel Create(DbConnection connection, IEnumerable tables, IEnumerable schemas) 36 | { 37 | var databaseModel = new DatabaseModel(); 38 | 39 | var connectionStartedOpen = connection.State == ConnectionState.Open; 40 | if (!connectionStartedOpen) 41 | { 42 | connection.Open(); 43 | } 44 | 45 | try 46 | { 47 | databaseModel.DefaultSchema = DatabaseModelDefaultSchema; 48 | 49 | GetTables(connection, null, databaseModel); 50 | 51 | return databaseModel; 52 | } 53 | finally 54 | { 55 | if (!connectionStartedOpen) 56 | { 57 | connection.Close(); 58 | } 59 | } 60 | } 61 | 62 | private void GetTables( 63 | DbConnection connection, 64 | Func tableFilter, 65 | DatabaseModel databaseModel) 66 | { 67 | using (var command = connection.CreateCommand()) 68 | { 69 | var commandText = @" 70 | SELECT 71 | t.""_File-Name"" AS 'name' 72 | FROM ""pub"".""_File"" t "; 73 | 74 | var filter = 75 | $"WHERE t.\"_File-Name\" <> '{HistoryRepository.DefaultTableName}' {(tableFilter != null ? $" AND {tableFilter("t.\"_file-name\"")}" : "")}"; 76 | 77 | command.CommandText = commandText + filter; 78 | 79 | using (var reader = command.ExecuteReader()) 80 | { 81 | while (reader.Read()) 82 | { 83 | var name = reader.GetValueOrDefault("name"); 84 | 85 | var table = new DatabaseTable 86 | { 87 | Schema = DatabaseModelDefaultSchema, 88 | Name = name 89 | }; 90 | 91 | databaseModel.Tables.Add(table); 92 | } 93 | } 94 | 95 | GetColumns(connection, filter, databaseModel); 96 | } 97 | } 98 | 99 | private void GetColumns( 100 | DbConnection connection, 101 | string tableFilter, 102 | DatabaseModel databaseModel) 103 | { 104 | using (var command = connection.CreateCommand()) 105 | { 106 | command.CommandText = new StringBuilder() 107 | .AppendLine("SELECT") 108 | .AppendLine(" f.\"_Field-Name\",") 109 | .AppendLine(" f.\"_Data-Type\",") 110 | .AppendLine(" t.\"_File-Name\" as name,") 111 | .AppendLine(" t.\"_Prime-Index\" as primeindex,") 112 | .AppendLine(" f.\"_Mandatory\",") 113 | .AppendLine(" if.\"_index-recid\" as identity,") 114 | .AppendLine(" f.\"_initial\"") 115 | .AppendLine("FROM pub.\"_field\" f") 116 | .AppendLine("INNER JOIN pub.\"_File\" t ") 117 | .AppendLine("ON t.rowid = f.\"_File-recid\"") 118 | .AppendLine("LEFT JOIN pub.\"_index-field\" if ") 119 | .AppendLine("ON if.\"_index-recid\" = t.\"_Prime-Index\" AND if.\"_field-recid\" = f.rowid") 120 | .AppendLine(tableFilter) 121 | .AppendLine("ORDER BY f.\"_Order\"") 122 | .ToString(); 123 | 124 | using (var reader = command.ExecuteReader()) 125 | { 126 | var tableColumnGroups = reader.Cast() 127 | .GroupBy( 128 | ddr => ddr.GetValueOrDefault("name")); 129 | 130 | foreach (var tableColumnGroup in tableColumnGroups) 131 | { 132 | var tableName = tableColumnGroup.Key; 133 | var table = databaseModel.Tables.Single(t => t.Schema == DatabaseModelDefaultSchema && t.Name == tableName); 134 | 135 | var primaryKey = new DatabasePrimaryKey 136 | { 137 | Table = table, 138 | Name = table + "_PK" 139 | }; 140 | 141 | table.PrimaryKey = primaryKey; 142 | 143 | foreach (var dataRecord in tableColumnGroup) 144 | { 145 | var columnName = dataRecord.GetValueOrDefault("_Field-Name"); 146 | var dataTypeName = dataRecord.GetValueOrDefault("_Data-Type"); 147 | var isNullable = !dataRecord.GetValueOrDefault("_Mandatory"); 148 | var isIdentity = dataRecord.GetValueOrDefault("identity") != null; 149 | var defaultValue = !isIdentity ? dataRecord.GetValueOrDefault("_initial") : null; 150 | 151 | var storeType = dataTypeName; 152 | if (string.IsNullOrWhiteSpace(defaultValue?.ToString())) 153 | { 154 | defaultValue = null; 155 | } 156 | 157 | table.Columns.Add(new DatabaseColumn 158 | { 159 | Table = table, 160 | Name = columnName, 161 | StoreType = storeType, 162 | IsNullable = isNullable, 163 | DefaultValueSql = defaultValue?.ToString(), 164 | ValueGenerated = default 165 | }); 166 | 167 | 168 | if (isIdentity) 169 | { 170 | var column = table.Columns.FirstOrDefault(c => c.Name == columnName) 171 | ?? table.Columns.FirstOrDefault(c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); 172 | primaryKey.Columns.Add(column); 173 | } 174 | } 175 | 176 | // OpenEdge supports having tables with no primary key 177 | if (!primaryKey.Columns.Any()) 178 | { 179 | databaseModel.Tables.Remove(table); 180 | } 181 | } 182 | } 183 | } 184 | } 185 | 186 | 187 | private static string DisplayName(string schema, string name) 188 | => (!string.IsNullOrEmpty(schema) ? schema + "." : "") + name; 189 | } 190 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Storage/IOpenEdgeRelationalConnection.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Storage; 2 | 3 | namespace EntityFrameworkCore.OpenEdge.Storage 4 | { 5 | public interface IOpenEdgeRelationalConnection : IRelationalConnection 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Storage/Internal/IOpenEdgeSqlGenerationHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Storage; 2 | 3 | namespace EntityFrameworkCore.OpenEdge.Storage.Internal 4 | { 5 | public interface IOpenEdgeSqlGenerationHelper : ISqlGenerationHelper 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Storage/Internal/Mapping/OpenEdgeBoolTypeMapping.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | using Microsoft.EntityFrameworkCore.Storage; 3 | 4 | namespace EntityFrameworkCore.OpenEdge.Storage.Internal.Mapping 5 | { 6 | public class OpenEdgeBoolTypeMapping : BoolTypeMapping 7 | { 8 | public OpenEdgeBoolTypeMapping() 9 | : base("bit") 10 | { 11 | } 12 | 13 | protected OpenEdgeBoolTypeMapping(RelationalTypeMappingParameters parameters) 14 | : base(parameters) 15 | { 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Storage/Internal/Mapping/OpenEdgeTypeMappingSource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using Microsoft.EntityFrameworkCore.Storage; 5 | 6 | namespace EntityFrameworkCore.OpenEdge.Storage.Internal.Mapping 7 | { 8 | public class OpenEdgeTypeMappingSource : RelationalTypeMappingSource 9 | { 10 | private const int VarcharMaxSize = 32000; 11 | 12 | private readonly DateTimeTypeMapping _datetime = new DateTimeTypeMapping("datetime", DbType.DateTime); 13 | private readonly DateTimeOffsetTypeMapping _datetimeOffset = new DateTimeOffsetTypeMapping("datetime-tz", DbType.DateTimeOffset); 14 | private readonly DateTimeTypeMapping _date = new DateTimeTypeMapping("date", DbType.Date); 15 | private readonly DateTimeTypeMapping _timeStamp = new DateTimeTypeMapping("timestamp", DbType.DateTime); 16 | private readonly TimeSpanTypeMapping _time = new TimeSpanTypeMapping("time", DbType.Time); 17 | 18 | private readonly OpenEdgeBoolTypeMapping _boolean = new OpenEdgeBoolTypeMapping(); 19 | private readonly ShortTypeMapping _smallint = new ShortTypeMapping("smallint", DbType.Int16); 20 | private readonly ShortTypeMapping _tinyint = new ShortTypeMapping("tinyint", DbType.Byte); 21 | private readonly IntTypeMapping _integer = new IntTypeMapping("integer", DbType.Int32); 22 | private readonly LongTypeMapping _bigint = new LongTypeMapping("bigint"); 23 | 24 | private readonly StringTypeMapping _char = new StringTypeMapping("char", DbType.String); 25 | private readonly StringTypeMapping _varchar = new StringTypeMapping("varchar", DbType.AnsiString); 26 | 27 | private readonly ByteArrayTypeMapping _binary = new ByteArrayTypeMapping("binary", DbType.Binary); 28 | 29 | private readonly FloatTypeMapping _float = new FloatTypeMapping("real"); 30 | private readonly DoubleTypeMapping _double = new DoubleTypeMapping("double precision"); 31 | private readonly DecimalTypeMapping _decimal = new DecimalTypeMapping("decimal"); 32 | 33 | private readonly Dictionary _storeTypeMappings; 34 | private readonly Dictionary _clrTypeMappings; 35 | 36 | public OpenEdgeTypeMappingSource(TypeMappingSourceDependencies dependencies, RelationalTypeMappingSourceDependencies relationalDependencies) 37 | : base(dependencies, relationalDependencies) 38 | { 39 | _clrTypeMappings 40 | = new Dictionary 41 | { 42 | { typeof(int), _integer }, 43 | { typeof(long), _bigint }, 44 | { typeof(DateTime), _datetime }, 45 | { typeof(bool), _boolean }, 46 | { typeof(byte), _tinyint }, 47 | { typeof(byte[]), _binary}, 48 | { typeof(double), _double }, 49 | { typeof(DateTimeOffset), _datetime }, 50 | { typeof(short), _smallint }, 51 | { typeof(float), _float }, 52 | { typeof(decimal), _decimal }, 53 | { typeof(TimeSpan), _time } 54 | }; 55 | 56 | _storeTypeMappings 57 | = new Dictionary(StringComparer.OrdinalIgnoreCase) 58 | { 59 | { "bigint", _bigint }, 60 | { "int64", _bigint }, 61 | { "binary varying", _binary }, 62 | { "raw", _binary }, 63 | { "binary", _binary }, 64 | { "blob", _binary }, 65 | { "bit", _boolean}, 66 | { "logical", _boolean}, 67 | { "char varying", _char }, 68 | { "char", _char }, 69 | { "character varying", _char }, 70 | { "character", _char }, 71 | { "clob", _char }, 72 | { "date", _date }, 73 | { "datetime", _datetime }, 74 | { "datetime2", _datetime }, 75 | { "datetimeoffset", _datetimeOffset }, 76 | { "datetime-tz", _datetimeOffset }, 77 | { "dec", _decimal }, 78 | { "decimal", _decimal }, 79 | { "double precision", _double }, 80 | { "double", _double }, 81 | { "float", _double }, 82 | { "image", _binary }, 83 | { "int", _integer }, 84 | { "integer", _integer }, 85 | { "money", _decimal }, 86 | { "numeric", _decimal }, 87 | { "real", _float }, 88 | { "recid", _char }, 89 | { "smalldatetime", _datetime }, 90 | { "smallint", _smallint}, 91 | { "short", _smallint}, 92 | { "smallmoney", _decimal }, 93 | { "text", _char}, 94 | { "time", _time }, 95 | { "timestamp", _timeStamp }, 96 | { "tinyint", _tinyint}, 97 | { "varbinary", _binary }, 98 | { "varchar", _varchar } 99 | }; 100 | } 101 | 102 | protected override RelationalTypeMapping FindMapping(in RelationalTypeMappingInfo mappingInfo) 103 | { 104 | return FindRawMapping(mappingInfo)?.Clone(mappingInfo); 105 | } 106 | 107 | private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingInfo) 108 | { 109 | var clrType = mappingInfo.ClrType; 110 | var storeTypeName = mappingInfo.StoreTypeName; 111 | var storeTypeNameBase = mappingInfo.StoreTypeNameBase; 112 | 113 | if (storeTypeName != null) 114 | { 115 | if (clrType == typeof(float) 116 | && mappingInfo.Size != null 117 | && mappingInfo.Size <= 24 118 | && (storeTypeNameBase.Equals("float", StringComparison.OrdinalIgnoreCase) 119 | || storeTypeNameBase.Equals("double precision", StringComparison.OrdinalIgnoreCase))) 120 | { 121 | return _float; 122 | } 123 | 124 | if (_storeTypeMappings.TryGetValue(storeTypeName, out var mapping) 125 | || _storeTypeMappings.TryGetValue(storeTypeNameBase, out mapping)) 126 | { 127 | return clrType == null 128 | || mapping.ClrType == clrType 129 | ? mapping 130 | : null; 131 | } 132 | } 133 | 134 | if (clrType != null) 135 | { 136 | if (_clrTypeMappings.TryGetValue(clrType, out var mapping)) 137 | { 138 | return mapping; 139 | } 140 | 141 | if (clrType == typeof(string)) 142 | { 143 | var isAnsi = mappingInfo.IsUnicode == false; 144 | var isFixedLength = mappingInfo.IsFixedLength == true; 145 | var baseName = (isFixedLength ? "CHAR" : "VARCHAR"); 146 | var maxSize = VarcharMaxSize; 147 | 148 | var size = (int?)(mappingInfo.Size ?? maxSize); 149 | if (size > maxSize) 150 | { 151 | size = null; 152 | } 153 | 154 | var dbType = isAnsi 155 | ? (isFixedLength ? DbType.AnsiStringFixedLength : DbType.AnsiString) 156 | : (isFixedLength ? DbType.StringFixedLength : (DbType?)null); 157 | 158 | 159 | return new StringTypeMapping( 160 | baseName + "(" + (size == null ? "max" : size.ToString()) + ")", 161 | dbType, 162 | !isAnsi, 163 | size); 164 | } 165 | } 166 | 167 | return null; 168 | } 169 | } 170 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Storage/Internal/OpenEdgeSqlGenerationHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using Microsoft.EntityFrameworkCore.Storage; 3 | 4 | namespace EntityFrameworkCore.OpenEdge.Storage.Internal 5 | { 6 | public class OpenEdgeSqlGenerationHelper : RelationalSqlGenerationHelper, IOpenEdgeSqlGenerationHelper 7 | { 8 | public OpenEdgeSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependencies) 9 | : base(dependencies) 10 | { 11 | 12 | } 13 | 14 | public override string StatementTerminator { get; } = ""; 15 | 16 | 17 | public override void DelimitIdentifier(StringBuilder builder, string identifier) 18 | { 19 | // Row ID cannot be delimited in OpenEdge 20 | if (identifier == "rowid") 21 | { 22 | EscapeIdentifier(builder, identifier); 23 | return; 24 | } 25 | 26 | base.DelimitIdentifier(builder, identifier); 27 | } 28 | 29 | public override string DelimitIdentifier(string identifier) 30 | { 31 | // Row ID cannot be delimited in OpenEdge 32 | if (identifier == "rowid") 33 | { 34 | return EscapeIdentifier(identifier); 35 | } 36 | 37 | return base.DelimitIdentifier(identifier); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Storage/OpenEdgeRelationalConnection.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | using System.Data.Odbc; 3 | using Microsoft.EntityFrameworkCore.Storage; 4 | 5 | namespace EntityFrameworkCore.OpenEdge.Storage 6 | { 7 | public class OpenEdgeRelationalConnection : RelationalConnection, IOpenEdgeRelationalConnection 8 | { 9 | public OpenEdgeRelationalConnection(RelationalConnectionDependencies dependencies) 10 | : base(dependencies) 11 | { 12 | } 13 | 14 | protected override DbConnection CreateDbConnection() 15 | => new OdbcConnection(ConnectionString); 16 | } 17 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Update/IOpenEdgeUpdateSqlGenerator.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Update; 2 | 3 | namespace EntityFrameworkCore.OpenEdge.Update 4 | { 5 | public interface IOpenEdgeUpdateSqlGenerator :IUpdateSqlGenerator 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Update/Internal/OpenEdgeModificationCommandBatchFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Infrastructure; 2 | using Microsoft.EntityFrameworkCore.Storage; 3 | using Microsoft.EntityFrameworkCore.Update; 4 | 5 | namespace EntityFrameworkCore.OpenEdge.Update.Internal 6 | { 7 | public class OpenEdgeModificationCommandBatchFactory : IModificationCommandBatchFactory 8 | { 9 | private readonly IRelationalCommandBuilderFactory _commandBuilderFactory; 10 | private readonly ISqlGenerationHelper _sqlGenerationHelper; 11 | private readonly IRelationalValueBufferFactoryFactory _valueBufferFactoryFactory; 12 | private readonly IDbContextOptions _options; 13 | private readonly IUpdateSqlGenerator _updateSqlGenerator; 14 | 15 | public OpenEdgeModificationCommandBatchFactory(IRelationalCommandBuilderFactory commandBuilderFactory, ISqlGenerationHelper sqlGenerationHelper, 16 | IUpdateSqlGenerator updateSqlGenerator, IRelationalValueBufferFactoryFactory valueBufferFactoryFactory, IDbContextOptions options) 17 | { 18 | _commandBuilderFactory = commandBuilderFactory; 19 | _sqlGenerationHelper = sqlGenerationHelper; 20 | _updateSqlGenerator = updateSqlGenerator; 21 | _valueBufferFactoryFactory = valueBufferFactoryFactory; 22 | _options = options; 23 | } 24 | 25 | public virtual ModificationCommandBatch Create() 26 | => new OpenEdgeSingularModificationCommandBatch( 27 | _commandBuilderFactory, 28 | _sqlGenerationHelper, 29 | _updateSqlGenerator, 30 | _valueBufferFactoryFactory); 31 | } 32 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Update/OpenEdgeSingularModificationCommandBatch.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Microsoft.EntityFrameworkCore.Storage; 4 | using Microsoft.EntityFrameworkCore.Update; 5 | 6 | namespace EntityFrameworkCore.OpenEdge.Update 7 | { 8 | public class OpenEdgeSingularModificationCommandBatch : SingularModificationCommandBatch 9 | { 10 | private readonly IRelationalCommandBuilderFactory _commandBuilderFactory; 11 | 12 | public OpenEdgeSingularModificationCommandBatch(IRelationalCommandBuilderFactory commandBuilderFactory, ISqlGenerationHelper sqlGenerationHelper, IUpdateSqlGenerator updateSqlGenerator, IRelationalValueBufferFactoryFactory valueBufferFactoryFactory) : base(commandBuilderFactory, sqlGenerationHelper, updateSqlGenerator, valueBufferFactoryFactory) 13 | { 14 | _commandBuilderFactory = commandBuilderFactory; 15 | } 16 | 17 | protected override RawSqlCommand CreateStoreCommand() 18 | { 19 | var commandBuilder = _commandBuilderFactory 20 | .Create() 21 | .Append(GetCommandText()); 22 | 23 | var parameterValues = new Dictionary(GetParameterCount()); 24 | 25 | for (var commandIndex = 0; commandIndex < ModificationCommands.Count; commandIndex++) 26 | { 27 | var command = ModificationCommands[commandIndex]; 28 | 29 | foreach (var columnModification in command.ColumnModifications 30 | .OrderBy(cm => cm.IsCondition)) 31 | { 32 | if (columnModification.UseCurrentValueParameter) 33 | { 34 | commandBuilder.AddParameter(columnModification.ParameterName, 35 | SqlGenerationHelper.GenerateParameterName(columnModification.ParameterName), 36 | columnModification.Property); 37 | 38 | parameterValues.Add(columnModification.ParameterName, columnModification.Value); 39 | } 40 | 41 | if (columnModification.UseOriginalValueParameter) 42 | { 43 | commandBuilder.AddParameter(columnModification.OriginalParameterName, 44 | SqlGenerationHelper.GenerateParameterName(columnModification.OriginalParameterName), 45 | columnModification.Property); 46 | 47 | parameterValues.Add(columnModification.OriginalParameterName, columnModification.OriginalValue); 48 | } 49 | } 50 | } 51 | 52 | return new RawSqlCommand(commandBuilder.Build(), parameterValues); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/EFCore.OpenEdge/Update/OpenEdgeUpdateSqlGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using EntityFrameworkCore.OpenEdge.Extensions; 8 | using Microsoft.EntityFrameworkCore.Metadata; 9 | using Microsoft.EntityFrameworkCore.Storage; 10 | using Microsoft.EntityFrameworkCore.Update; 11 | 12 | namespace EntityFrameworkCore.OpenEdge.Update 13 | { 14 | public class OpenEdgeUpdateSqlGenerator : UpdateSqlGenerator, IOpenEdgeUpdateSqlGenerator 15 | { 16 | public OpenEdgeUpdateSqlGenerator(UpdateSqlGeneratorDependencies dependencies) : base(dependencies) 17 | { 18 | } 19 | 20 | protected override void AppendRowsAffectedWhereCondition(StringBuilder commandStringBuilder, int expectedRowsAffected) 21 | { 22 | commandStringBuilder 23 | .Append("1 = 1"); 24 | } 25 | 26 | protected override void AppendIdentityWhereCondition(StringBuilder commandStringBuilder, ColumnModification columnModification) 27 | { 28 | commandStringBuilder 29 | .Append("1 = 1"); 30 | } 31 | 32 | 33 | protected override void AppendValues(StringBuilder commandStringBuilder, IReadOnlyList operations) 34 | { 35 | bool useLiterals = true; 36 | 37 | if (operations.Count > 0) 38 | { 39 | commandStringBuilder 40 | .Append("(") 41 | .AppendJoin( 42 | operations, 43 | SqlGenerationHelper, 44 | 45 | (sb, o, helper) => 46 | { 47 | if (useLiterals) 48 | { 49 | AppendSqlLiteral(sb, o.Value, o.Property); 50 | } 51 | else 52 | { 53 | // Use '?' rather than named parameters 54 | AppendParameter(sb, o); 55 | } 56 | }) 57 | .Append(")"); 58 | } 59 | } 60 | 61 | private void AppendParameter(StringBuilder commandStringBuilder, ColumnModification modification) 62 | { 63 | commandStringBuilder.Append(modification.IsWrite ? "?" : "DEFAULT"); 64 | } 65 | 66 | private void AppendSqlLiteral(StringBuilder commandStringBuilder, object value, IProperty property) 67 | { 68 | var mapping = property != null 69 | ? Dependencies.TypeMappingSource.FindMapping(property) 70 | : null; 71 | mapping = mapping ?? Dependencies.TypeMappingSource.GetMappingForValue(value); 72 | commandStringBuilder.Append(mapping.GenerateProviderValueSqlLiteral(value)); 73 | } 74 | 75 | 76 | protected override void AppendUpdateCommandHeader(StringBuilder commandStringBuilder, string name, string schema, 77 | IReadOnlyList operations) 78 | { 79 | commandStringBuilder.Append("UPDATE "); 80 | SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, name, schema); 81 | commandStringBuilder.Append(" SET ") 82 | .AppendJoin( 83 | operations, 84 | SqlGenerationHelper, 85 | (sb, o, helper) => 86 | { 87 | helper.DelimitIdentifier(sb, o.ColumnName); 88 | sb.Append(" = "); 89 | if (!o.UseCurrentValueParameter) 90 | { 91 | AppendSqlLiteral(sb, o.Value, o.Property); 92 | } 93 | else 94 | { 95 | sb.Append("?"); 96 | } 97 | }); 98 | } 99 | 100 | protected override void AppendWhereCondition(StringBuilder commandStringBuilder, ColumnModification columnModification, 101 | bool useOriginalValue) 102 | { 103 | SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, columnModification.ColumnName); 104 | 105 | var parameterValue = useOriginalValue 106 | ? columnModification.OriginalValue 107 | : columnModification.Value; 108 | 109 | if (parameterValue == null) 110 | { 111 | base.AppendWhereCondition(commandStringBuilder, columnModification, useOriginalValue); 112 | } 113 | else 114 | { 115 | commandStringBuilder.Append(" = "); 116 | if (!columnModification.UseCurrentValueParameter 117 | && !columnModification.UseOriginalValueParameter) 118 | { 119 | base.AppendWhereCondition(commandStringBuilder, columnModification, useOriginalValue); 120 | } 121 | else 122 | { 123 | commandStringBuilder.Append("?"); 124 | } 125 | } 126 | } 127 | 128 | public override ResultSetMapping AppendInsertOperation(StringBuilder commandStringBuilder, ModificationCommand command, 129 | int commandPosition) 130 | { 131 | 132 | var name = command.TableName; 133 | var schema = command.Schema; 134 | var operations = command.ColumnModifications; 135 | 136 | var writeOperations = operations.Where(o => o.IsWrite) 137 | .Where(o => o.ColumnName != "rowid") 138 | .ToList(); 139 | 140 | AppendInsertCommand(commandStringBuilder, name, schema, writeOperations); 141 | 142 | return ResultSetMapping.NoResultSet; 143 | } 144 | 145 | public override ResultSetMapping AppendUpdateOperation(StringBuilder commandStringBuilder, ModificationCommand command, 146 | int commandPosition) 147 | { 148 | var name = command.TableName; 149 | var schema = command.Schema; 150 | var operations = command.ColumnModifications; 151 | 152 | var writeOperations = operations.Where(o => o.IsWrite).ToList(); 153 | var conditionOperations = operations.Where(o => o.IsCondition).ToList(); 154 | 155 | AppendUpdateCommand(commandStringBuilder, name, schema, writeOperations, conditionOperations); 156 | 157 | return AppendSelectAffectedCountCommand(commandStringBuilder, name, schema, commandPosition); 158 | } 159 | } 160 | } --------------------------------------------------------------------------------