├── .gitattributes ├── .gitignore ├── LICENSE.md ├── README.md ├── build ├── EntityFramework.BulkInsert.MySql.nuspec ├── EntityFramework.BulkInsert.SqlServerCe.nuspec ├── EntityFramework.BulkInsert.nuspec ├── build-all.cmd ├── build-bulkinsert.cmd ├── build-bulkinsert.mysql.cmd ├── build-bulkinsert.sqlce.cmd ├── build.cmd └── build.ps1 ├── src ├── .editorconfig ├── Common │ └── CommonAssemblyInfo.cs ├── EntityFramework.BulkInsert.MvcTest │ └── EntityFramework.BulkInsert.MvcTest.csproj ├── EntityFramework.BulkInsert.MySql │ ├── App.config │ ├── EntityFramework.BulkInsert.MySql.csproj │ ├── MySqlBulkInsertProvider.cs │ ├── MySqlEngine.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config ├── EntityFramework.BulkInsert.SqlServerCe.Net40 │ ├── Class1.cs │ ├── EntityFramework.BulkInsert.SqlServerCe.Net40.csproj │ └── Properties │ │ └── AssemblyInfo.cs ├── EntityFramework.BulkInsert.SqlServerCe │ ├── App.config │ ├── EntityFramework.BulkInsert.SqlServerCe.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SqlCeBulkInsertProvider.cs │ └── packages.config ├── EntityFramework.BulkInsert.Test │ ├── App.config │ ├── App_Start │ │ └── EntityFramework.SqlServerCompact.cs │ ├── CodeFirst │ │ ├── BulkInsert │ │ │ ├── BulkInsertTestBase.cs │ │ │ ├── MySql │ │ │ │ ├── MySqlBulkInsertPerformanceTest.cs │ │ │ │ └── MySqlBulkInsertTest.cs │ │ │ ├── PerformanceTestBase.cs │ │ │ ├── SqlCe │ │ │ │ └── SqlCeBulkInsertTest.cs │ │ │ └── SqlServer │ │ │ │ ├── SqlBulkInsertPerformanceTest.cs │ │ │ │ ├── SqlBulkInsertTest.cs │ │ │ │ ├── SqlBulkInsertWithDataTable.cs │ │ │ │ └── SqlBulkInsertWithDataTablePerformance.cs │ │ ├── Domain │ │ │ ├── Company.cs │ │ │ ├── CompanySize.cs │ │ │ ├── ComplexTypes │ │ │ │ ├── Address.cs │ │ │ │ └── Contact.cs │ │ │ ├── Contract.cs │ │ │ ├── Employee.cs │ │ │ ├── Entity.cs │ │ │ ├── EntityWithTypedId.cs │ │ │ ├── Foo.cs │ │ │ ├── ICreatedAt.cs │ │ │ ├── IModifiedAt.cs │ │ │ ├── MeteringPoint.cs │ │ │ ├── Page.cs │ │ │ ├── PageTranslations.cs │ │ │ ├── PinPoint.cs │ │ │ ├── Reading.cs │ │ │ └── TestUser.cs │ │ ├── MappingTest.cs │ │ ├── MySqlContext.cs │ │ ├── SqlCeContext.cs │ │ ├── SqlContext.cs │ │ ├── TestBase.cs │ │ └── TestBaseContext.cs │ ├── CustomProvider │ │ └── SqlCeTest.cs │ ├── DataTableHelperTest.cs │ ├── DatabaseFirst │ │ ├── Authors.cs │ │ ├── Books.cs │ │ ├── DatabaseFirstTest.cs │ │ ├── Publishers.cs │ │ ├── TestDataModel.Context.cs │ │ ├── TestDataModel.Context.tt │ │ ├── TestDataModel.Designer.cs │ │ ├── TestDataModel.cs │ │ ├── TestDataModel.edmx │ │ ├── TestDataModel.edmx.diagram │ │ └── TestDataModel.tt │ ├── DbFirst │ │ ├── Blogs.cs │ │ ├── BulkInsertTest.cs │ │ ├── DbFirstModel.Context.cs │ │ ├── DbFirstModel.Context.tt │ │ ├── DbFirstModel.Designer.cs │ │ ├── DbFirstModel.cs │ │ ├── DbFirstModel.edmx │ │ ├── DbFirstModel.edmx.diagram │ │ ├── DbFirstModel.tt │ │ ├── MappingTest.cs │ │ ├── Posts.cs │ │ └── TestBase.cs │ ├── EntityFramework.BulkInsert.Test.csproj │ ├── EntityFramework.Bulkinsert.Test.Net40.csproj │ ├── Issue1344 │ │ ├── AccrualContext.cs │ │ ├── BaseXafConvention.cs │ │ ├── EfDbConfiguration.cs │ │ ├── IntervalEntity.cs │ │ ├── Post.cs │ │ ├── PostConfiguration.cs │ │ ├── Table Schema.jpg │ │ ├── XafEntity.cs │ │ └── XafGcEntity.cs │ ├── Issue1369 │ │ ├── CreditReportEntity.cs │ │ ├── Issue1369Context.cs │ │ └── LoanEntity.cs │ ├── MappedDataReaderTest.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config ├── EntityFramework.BulkInsert.sln ├── EntityFramework.BulkInsert │ ├── App.config │ ├── BulkCopyOptions.cs │ ├── BulkInsertDefaults.cs │ ├── BulkInsertOptions.cs │ ├── EntityFramework.BulkInsert.Net40.csproj │ ├── EntityFramework.BulkInsert.csproj │ ├── Exceptions │ │ ├── BulkInsertProviderNotFoundException.cs │ │ └── EntityTypeNotFoundException.cs │ ├── Extensions │ │ ├── BulkInsertExtension.cs │ │ ├── DbContextExtensions.cs │ │ └── TypeExtensions.cs │ ├── Helpers │ │ ├── DataTableHelper.cs │ │ └── MappedDataReader.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ProviderFactory.cs │ ├── Providers │ │ ├── EfSqlBulkInsertProviderWithDataTable.cs │ │ ├── IEfBulkInsertProvider.cs │ │ ├── ProviderBase.cs │ │ └── SqlBulkInsertProvider.cs │ ├── RowsCopiedEventArgs.cs │ ├── RowsCopiedEventHandler.cs │ └── packages.config └── EntityFramework.MappingAPI │ ├── App.config │ ├── EfMap.cs │ ├── EntityFramework.MappingAPI.csproj │ ├── Exceptions │ └── ParentNotMappedYetException.cs │ ├── Extensions │ ├── MappingApiExtensions.cs │ └── TypeExtensions.cs │ ├── IEntityMap.cs │ ├── IEntityMap`1.cs │ ├── IPropertyMap.cs │ ├── Mappers │ ├── CodeFirstMapper.cs │ ├── DbFirstMapper.cs │ ├── MapperBase.cs │ └── TphData.cs │ ├── Mappings │ ├── DbMapping.cs │ ├── EntityMap.cs │ ├── EntityMap`1.cs │ └── PropertyMap.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── packages.config └── tools ├── 7-zip ├── 7-zip.chm ├── 7za.exe ├── copying.txt ├── license.txt └── readme.txt ├── ILMerge ├── ILMerge.exe └── System.Compiler.dll ├── NUnit ├── framework │ ├── nunit.framework.dll │ ├── nunit.framework.xml │ ├── nunit.mocks.dll │ └── pnunit.framework.dll ├── lib │ ├── Images │ │ ├── Ellipsis.gif │ │ ├── Tree │ │ │ ├── Circles │ │ │ │ ├── Failure.jpg │ │ │ │ ├── Ignored.jpg │ │ │ │ ├── Inconclusive.jpg │ │ │ │ ├── Skipped.jpg │ │ │ │ └── Success.jpg │ │ │ ├── Classic │ │ │ │ ├── Failure.jpg │ │ │ │ ├── Ignored.jpg │ │ │ │ ├── Inconclusive.jpg │ │ │ │ ├── Skipped.jpg │ │ │ │ └── Success.jpg │ │ │ ├── Default │ │ │ │ ├── Failure.png │ │ │ │ ├── Ignored.png │ │ │ │ ├── Inconclusive.png │ │ │ │ ├── Skipped.png │ │ │ │ └── Success.png │ │ │ └── Visual Studio │ │ │ │ ├── Failure.png │ │ │ │ ├── Ignored.png │ │ │ │ ├── Inconclusive.png │ │ │ │ ├── SeriousWarning.png │ │ │ │ ├── Skipped.png │ │ │ │ └── Success.png │ │ ├── pinned.gif │ │ └── unpinned.gif │ ├── NSubstitute.dll │ ├── NSubstitute.xml │ ├── Rhino.Mocks.dll │ ├── Rhino.Mocks.xml │ ├── log4net.dll │ ├── nunit-console-runner.dll │ ├── nunit-gui-runner.dll │ ├── nunit.core.dll │ ├── nunit.core.interfaces.dll │ ├── nunit.uiexception.dll │ ├── nunit.uikit.dll │ └── nunit.util.dll ├── nunit-agent-x86.exe ├── nunit-agent-x86.exe.config ├── nunit-agent.exe ├── nunit-agent.exe.config ├── nunit-console-x86.exe ├── nunit-console-x86.exe.config ├── nunit-console.exe ├── nunit-console.exe.config ├── nunit-x86.exe ├── nunit-x86.exe.config ├── nunit.exe └── nunit.exe.config ├── NuGet └── NuGet.exe └── PSake ├── en-US └── psake.psm1-help.xml.old ├── private ├── CleanupEnvironment.ps1 ├── ConfigureBuildEnvironment.ps1 ├── CreateConfigurationForNewContext.ps1 ├── ExecuteInBuildFileScope.ps1 ├── Get-DefaultBuildFile.ps1 ├── GetCurrentConfigurationOrDefault.ps1 ├── GetTasksFromContext.ps1 ├── LoadConfiguration.ps1 ├── LoadModules.ps1 ├── ResolveError.ps1 ├── SelectObjectWithDefault.ps1 ├── WriteColoredOutput.ps1 ├── WriteDocumentation.ps1 └── WriteTaskTimeSummary.ps1 ├── psake-config.ps1 ├── psake.cmd ├── psake.ps1 ├── psake.psd1 ├── psake.psm1 └── public ├── Assert.ps1 ├── Exec.ps1 ├── FormatTaskName.ps1 ├── Framework.ps1 ├── Get-PSakeScriptTasks.ps1 ├── Include.ps1 ├── Invoke-Task.ps1 ├── Invoke-psake.ps1 ├── Properties.ps1 ├── Task.ps1 ├── TaskSetup.ps1 └── TaskTearDown.ps1 /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.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 | *.sln.GhostDoc.* 10 | 11 | # User-specific files (MonoDevelop/Xamarin Studio) 12 | *.userprefs 13 | 14 | # Build results 15 | [Dd]ebug/ 16 | [Dd]ebugPublic/ 17 | [Rr]elease/ 18 | [Rr]eleases/ 19 | x64/ 20 | x86/ 21 | build/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Dd]ist/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # DNX 46 | project.lock.json 47 | artifacts/ 48 | 49 | *_i.c 50 | *_p.c 51 | *_i.h 52 | *.ilk 53 | *.meta 54 | *.obj 55 | *.pch 56 | *.pdb 57 | *.pgc 58 | *.pgd 59 | *.rsp 60 | *.sbr 61 | *.tlb 62 | *.tli 63 | *.tlh 64 | *.tmp 65 | *.tmp_proj 66 | *.log 67 | *.vspscc 68 | *.vssscc 69 | .builds 70 | *.pidb 71 | *.svclog 72 | *.scc 73 | 74 | # Chutzpah Test files 75 | _Chutzpah* 76 | 77 | # Visual C++ cache files 78 | ipch/ 79 | *.aps 80 | *.ncb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | 90 | # TFS 2012 Local Workspace 91 | $tf/ 92 | 93 | # Guidance Automation Toolkit 94 | *.gpState 95 | 96 | # ReSharper is a .NET coding add-in 97 | _ReSharper*/ 98 | *.[Rr]e[Ss]harper 99 | *.DotSettings.user 100 | 101 | # JustCode is a .NET coding add-in 102 | .JustCode 103 | 104 | # TeamCity is a build add-in 105 | _TeamCity* 106 | 107 | # DotCover is a Code Coverage Tool 108 | *.dotCover 109 | 110 | # NCrunch 111 | _NCrunch_* 112 | .*crunch*.local.xml 113 | nCrunchTemp_* 114 | 115 | # MightyMoose 116 | *.mm.* 117 | AutoTest.Net/ 118 | 119 | # Web workbench (sass) 120 | .sass-cache/ 121 | 122 | # Installshield output folder 123 | [Ee]xpress/ 124 | 125 | # DocProject is a documentation generator add-in 126 | DocProject/buildhelp/ 127 | DocProject/Help/*.HxT 128 | DocProject/Help/*.HxC 129 | DocProject/Help/*.hhc 130 | DocProject/Help/*.hhk 131 | DocProject/Help/*.hhp 132 | DocProject/Help/Html2 133 | DocProject/Help/html 134 | 135 | # Click-Once directory 136 | publish/ 137 | 138 | # Publish Web Output 139 | *.[Pp]ublish.xml 140 | *.azurePubxml 141 | # TODO: Comment the next line if you want to checkin your web deploy settings 142 | # but database connection strings (with potential passwords) will be unencrypted 143 | # *.pubxml 144 | *.publishproj 145 | 146 | # NuGet Packages 147 | *.nupkg 148 | # The packages folder can be ignored because of Package Restore 149 | **/packages 150 | # except build/, which is used as an MSBuild target. 151 | !**/packages/build/ 152 | # Uncomment if necessary however generally it will be regenerated when needed 153 | #!**/packages/repositories.config 154 | 155 | # Windows Azure Build Output 156 | csx/ 157 | *.build.csdef 158 | 159 | # Windows Store app package directory 160 | AppPackages/ 161 | 162 | # Visual Studio cache files 163 | # files ending in .cache can be ignored 164 | *.[Cc]ache 165 | # but keep track of directories ending in .cache 166 | !*.[Cc]ache/ 167 | 168 | # Others 169 | ClientBin/ 170 | [Ss]tyle[Cc]op.* 171 | ~$* 172 | *~ 173 | *.dbmdl 174 | *.dbproj.schemaview 175 | *.pfx 176 | *.publishsettings 177 | node_modules/ 178 | bower_components/ 179 | orleans.codegen.cs 180 | 181 | # RIA/Silverlight projects 182 | Generated_Code/ 183 | 184 | # Backup & report files from converting an old project file 185 | # to a newer Visual Studio version. Backup files are not needed, 186 | # because we have git ;-) 187 | _UpgradeReport_Files/ 188 | Backup*/ 189 | UpgradeLog*.XML 190 | UpgradeLog*.htm 191 | 192 | # SQL Server files 193 | *.mdf 194 | *.ldf 195 | 196 | # Business Intelligence projects 197 | *.rdl.data 198 | *.bim.layout 199 | *.bim_*.settings 200 | 201 | # Microsoft Fakes 202 | FakesAssemblies/ 203 | 204 | # Node.js Tools for Visual Studio 205 | .ntvs_analysis.dat 206 | 207 | # Visual Studio 6 build log 208 | *.plg 209 | 210 | # Visual Studio 6 workspace options file 211 | *.opt 212 | 213 | # IntelliJ (Webstorm, etc...) 214 | .idea/ 215 | 216 | # Beyond Compare 217 | *.orig 218 | sh.exe.stackdump 219 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EntityFramework.BulkInsert 2 | Updated port of EntityFramework.BulkInsert from the original version on the Codeplex site. This is not my original project, this is to keep it going and add minor updates and support. The original was hosted on Codeplex but later taken down. Since then the project has seen support for async IO, bug fixes, explicit transaction support and support for MySql. 3 | 4 | # NuGet 5 | There are several NuGet packages available: 6 | * EntityFramework6.BulkInsert [![NuGet](https://img.shields.io/nuget/v/EntityFramework6.BulkInsert.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/EntityFramework6.BulkInsert/) 7 | 8 | * EntityFramework6.BulkInsert.SqlServerCe [![NuGet](https://img.shields.io/nuget/v/EntityFramework6.BulkInsert.SqlServerCe.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/EntityFramework6.BulkInsert.SqlServerCe/) 9 | 10 | * EntityFramework6.BulkInsert.MySql [![NuGet](https://img.shields.io/nuget/v/EntityFramework6.BulkInsert.MySql.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/EntityFramework6.BulkInsert.MySql/) 11 | 12 | # Purpose 13 | The purpose of this library is for performing Bulk Inserts using EntityFramework 6 and your existing `DbContext` instance to perform faster inserts instead of generating multiple insert statements for a collection of strongly typed objects. 14 | 15 | # Usage 16 | 17 | ```cs 18 | IEnumerable cars = GenerateCars(); 19 | 20 | using (var context = GetDbContext()) 21 | { 22 | context.BulkInsert(cars); 23 | } 24 | ``` 25 | 26 | Async IO support is also built in: 27 | 28 | ```cs 29 | IEnumerable cars = GenerateCars(); 30 | 31 | using (var context = GetDbContext()) 32 | { 33 | await context.BulkInsertAsync(cars); 34 | } 35 | ``` 36 | 37 | This library supports Explicit and Implicit transactions either using `IDbTransaction` or `TransactionScope` 38 | 39 | # Building 40 | To build/compile clone this repository and build: 41 | 42 | ``` 43 | git clone https://github.com/ghost1face/EntityFramework.BulkInsert.git 44 | ``` 45 | -------------------------------------------------------------------------------- /build/EntityFramework.BulkInsert.MySql.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | EntityFramework6.BulkInsert.MySql 5 | $version$ 6 | EntityFramework6.BulkInsert.MySql 7 | Daniel Destouche 8 | Daniel Destouche 9 | 10 | Fast Bulk insert extension for MySql using EntityFramework 6 11 | 12 | 13 | 14 | 15 | Fast Bulk insert extension for MySql using EntityFramework 6 16 | 17 | en-US 18 | https://github.com/ghost1face/EntityFramework.BulkInsert 19 | https://nuget.org/Content/Images/packageDefaultIcon-50x50.png 20 | true 21 | Apache-2.0 22 | Copyright 2019 23 | data ef ef6 code-first batch bulk insert mysql 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /build/EntityFramework.BulkInsert.SqlServerCe.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | EntityFramework6.BulkInsert.SqlServerCe 5 | $version$ 6 | EntityFramework6.BulkInsert.SqlServerCe 7 | Daniel Destouche 8 | Daniel Destouche 9 | 10 | Fast Bulk insert extension for SqlServerCe using EntityFramework 6 11 | 12 | 13 | 14 | 15 | Fast Bulk insert extension for SqlServerCe using EntityFramework 6 16 | 17 | en-US 18 | https://github.com/ghost1face/EntityFramework.BulkInsert 19 | https://nuget.org/Content/Images/packageDefaultIcon-50x50.png 20 | true 21 | Apache-2.0 22 | Copyright 2019 23 | data ef ef6 code-first batch bulk insert 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /build/EntityFramework.BulkInsert.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | EntityFramework6.BulkInsert 5 | $version$ 6 | EntityFramework6.BulkInsert 7 | Daniel Destouche 8 | Daniel Destouche 9 | 10 | Fast Bulk insert extension for EntityFramework 6 11 | 12 | 13 | 14 | 15 | Fast Bulk insert extension for EntityFramework 6 16 | 17 | en-US 18 | https://github.com/ghost1face/EntityFramework.BulkInsert 19 | https://nuget.org/Content/Images/packageDefaultIcon-50x50.png 20 | true 21 | Apache-2.0 22 | Copyright 2019 23 | data ef ef6 code-first batch bulk insert 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /build/build-all.cmd: -------------------------------------------------------------------------------- 1 | build -f '4.5' -------------------------------------------------------------------------------- /build/build-bulkinsert.cmd: -------------------------------------------------------------------------------- 1 | build -f '4.5' -parameters @{'project'='EntityFramework.BulkInsert'} -------------------------------------------------------------------------------- /build/build-bulkinsert.mysql.cmd: -------------------------------------------------------------------------------- 1 | build -f '4.5' -parameters @{'project'='EntityFramework.BulkInsert.MySql'} -------------------------------------------------------------------------------- /build/build-bulkinsert.sqlce.cmd: -------------------------------------------------------------------------------- 1 | build -f '4.5' -parameters @{'project'='EntityFramework.BulkInsert.SqlServerCe'} -------------------------------------------------------------------------------- /build/build.cmd: -------------------------------------------------------------------------------- 1 | powershell -Command "& { [Console]::WindowWidth = 150; [Console]::WindowHeight = 50; Start-Transcript runbuild.txt; Import-Module ..\Tools\PSake\psake.psm1; Invoke-psake .\build.ps1 %*; Stop-Transcript; }" 2 | pause -------------------------------------------------------------------------------- /src/.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | # Default settings: 5 | [*] 6 | insert_final_newline = false 7 | indent_style = space 8 | indent_size = 4 9 | end_of_line = crlf 10 | 11 | [{app.config,App.config}] 12 | indent_style = space 13 | indent_size = 2 14 | 15 | [*.cs] 16 | # new line preferences 17 | csharp_new_line_before_catch = true 18 | csharp_new_line_before_else = true 19 | csharp_new_line_before_finally = true 20 | csharp_new_line_before_open_brace = all 21 | csharp_new_line_before_members_in_anonymous_types = true 22 | csharp_new_line_before_members_in_object_initializers = true 23 | 24 | # prefer variable inlining 25 | csharp_style_inlined_variable_declaration = true:suggestion 26 | 27 | # use var when type is apparent 28 | csharp_style_var_when_type_is_apparent = true:suggestion 29 | 30 | # expression-level preferences 31 | dotnet_style_object_initializer = true:suggestion 32 | dotnet_style_collection_initializer = true:suggestion 33 | dotnet_style_coalesce_expression = true:suggestion 34 | 35 | # code style defaults 36 | csharp_preserve_single_line_blocks = true 37 | csharp_preserve_single_line_statements = false 38 | 39 | # space preferences 40 | csharp_space_after_cast = false 41 | csharp_space_after_colon_in_inheritance_clause = true 42 | csharp_space_after_comma = true 43 | csharp_space_after_dot = false 44 | csharp_space_after_keywords_in_control_flow_statements = true 45 | csharp_space_after_semicolon_in_for_statement = true 46 | csharp_space_around_binary_operators = before_and_after 47 | csharp_space_before_colon_in_inheritance_clause = true 48 | csharp_space_before_comma = false 49 | csharp_space_before_dot = false 50 | csharp_space_before_open_square_brackets = false 51 | csharp_space_before_semicolon_in_for_statement = false 52 | csharp_space_between_empty_square_brackets = false 53 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 54 | csharp_space_between_method_call_name_and_opening_parenthesis = false 55 | csharp_space_between_method_call_parameter_list_parentheses = false 56 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 57 | csharp_space_between_method_declaration_name_and_open_parenthesis = false 58 | csharp_space_between_method_declaration_parameter_list_parentheses = false 59 | csharp_space_between_square_brackets = false -------------------------------------------------------------------------------- /src/Common/CommonAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyCopyright("Copyright © 2019")] 4 | 5 | // Version information for an assembly consists of the following four values: 6 | // 7 | // Major Version 8 | // Minor Version 9 | // Build Number 10 | // Revision 11 | // 12 | // You can specify all the values or you can default the Build and Revision Numbers 13 | // by using the '*' as shown below: 14 | // [assembly: AssemblyVersion("1.0.*")] 15 | 16 | #if EF4 17 | [assembly: AssemblyVersion("4.1.0.25")] 18 | [assembly: AssemblyFileVersion("4.1.0.25")] 19 | #endif 20 | #if EF5 21 | [assembly: AssemblyVersion("5.0.0.25")] 22 | [assembly: AssemblyFileVersion("5.0.0.25")] 23 | #endif 24 | #if EF6 25 | [assembly: AssemblyVersion("6.0.3.10")] 26 | [assembly: AssemblyFileVersion("6.0.3.10")] 27 | #endif 28 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.MySql/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.MySql/MySqlEngine.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFramework.BulkInsert.MySql 2 | { 3 | internal enum MySqlEngine 4 | { 5 | MyISAM, 6 | InnoDB, 7 | Memory, 8 | CSV, 9 | Merge, 10 | Archive, 11 | Federated, 12 | Blackhole 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.MySql/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("EntityFramework.BulkInsert.MySql")] 8 | [assembly: AssemblyDescription("Fast Bulk insert extension for MySql using EntityFramework 6")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("EntityFramework.BulkInsert.MySql")] 12 | [assembly: AssemblyTrademark("")] 13 | [assembly: AssemblyCulture("")] 14 | 15 | // Setting ComVisible to false makes the types in this assembly not visible 16 | // to COM components. If you need to access a type in this assembly from 17 | // COM, set the ComVisible attribute to true on that type. 18 | [assembly: ComVisible(false)] 19 | 20 | // The following GUID is for the ID of the typelib if this project is exposed to COM 21 | [assembly: Guid("70daddaf-9ff3-4c69-af20-53d7ea0407a2")] 22 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.MySql/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.SqlServerCe.Net40/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace EntityFramework.BulkInsert.SqlServerCe.Net40 8 | { 9 | public class Class1 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.SqlServerCe.Net40/EntityFramework.BulkInsert.SqlServerCe.Net40.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {CB7718F0-634D-4E17-BB72-8040E8870618} 8 | Library 9 | Properties 10 | EntityFramework.BulkInsert.SqlServerCe 11 | EntityFramework.BulkInsert.SqlServerCe 12 | v4.0 13 | 512 14 | SAK 15 | SAK 16 | SAK 17 | SAK 18 | 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 58 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.SqlServerCe.Net40/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("EntityFramework.BulkInsert.SqlServerCe.Net40")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("EntityFramework.BulkInsert.SqlServerCe.Net40")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9ba8bfcb-917d-490b-bf01-b4a8157c026a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.SqlServerCe/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.SqlServerCe/EntityFramework.BulkInsert.SqlServerCe.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | NET45_EF6 6 | AnyCPU 7 | {8BCCBC7B-9F9F-491A-8778-88EF6D2A279C} 8 | Library 9 | Properties 10 | EntityFramework.BulkInsert.SqlServerCe 11 | EntityFramework.BulkInsert.SqlServerCe 12 | v4.5 13 | 512 14 | 15 | 16 | pdbonly 17 | true 18 | bin\Release\ 19 | TRACE 20 | prompt 21 | 4 22 | 23 | 24 | bin\NET45_EF4\ 25 | TRACE;DEBUG;NET45;EF4 26 | 27 | 28 | bin\NET45_EF5\ 29 | TRACE;DEBUG;NET45;EF5 30 | pdbonly 31 | true 32 | 33 | 34 | bin\NET45_EF6\ 35 | TRACE;DEBUG;NET45;EF6 36 | pdbonly 37 | true 38 | 39 | 40 | false 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll 53 | False 54 | 55 | 56 | ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll 57 | False 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | Properties\CommonAssemblyInfo.cs 70 | 71 | 72 | 73 | Code 74 | 75 | 76 | 77 | 78 | {E48AB221-FB79-4F22-9641-3C283F44F1C7} 79 | EntityFramework.BulkInsert 80 | 81 | 82 | {9AEB6EB0-F898-43CF-B894-BD8E52428E7C} 83 | EntityFramework.MappingAPI 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 98 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.SqlServerCe/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("EntityFramework.BulkInsert.SqlServerCe")] 8 | [assembly: AssemblyDescription("Fast Bulk insert extension for SqlServerCe using EntityFramework 6")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("EntityFramework.BulkInsert.SqlServerCe")] 12 | [assembly: AssemblyTrademark("")] 13 | [assembly: AssemblyCulture("")] 14 | 15 | // Setting ComVisible to false makes the types in this assembly not visible 16 | // to COM components. If you need to access a type in this assembly from 17 | // COM, set the ComVisible attribute to true on that type. 18 | [assembly: ComVisible(false)] 19 | 20 | // The following GUID is for the ID of the typelib if this project is exposed to COM 21 | [assembly: Guid("2f189706-9d05-4515-a42b-c580b31160c1")] -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.SqlServerCe/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/App_Start/EntityFramework.SqlServerCompact.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Entity; 2 | using System.Data.Entity.Infrastructure; 3 | 4 | [assembly: WebActivator.PreApplicationStartMethod(typeof(EntityFramework.Bulkinsert.Test.App_Start.EntityFramework_SqlServerCompact), "Start")] 5 | 6 | namespace EntityFramework.Bulkinsert.Test.App_Start { 7 | public static class EntityFramework_SqlServerCompact { 8 | public static void Start() { 9 | Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/BulkInsert/MySql/MySqlBulkInsertPerformanceTest.cs: -------------------------------------------------------------------------------- 1 | using EntityFramework.BulkInsert.MySql; 2 | 3 | namespace EntityFramework.BulkInsert.Test.CodeFirst.BulkInsert.MySql 4 | { 5 | public class MySqlBulkInsertPerformanceTest : PerformanceTestBase 6 | { 7 | protected override string ProviderConnectionType 8 | { 9 | get { return "MySql.Data.MySqlClient.MySqlConnection"; } 10 | } 11 | 12 | protected override MySqlContext GetContext() 13 | { 14 | return new MySqlContext(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/BulkInsert/MySql/MySqlBulkInsertTest.cs: -------------------------------------------------------------------------------- 1 | using EntityFramework.BulkInsert.MySql; 2 | using NUnit.Framework; 3 | 4 | namespace EntityFramework.BulkInsert.Test.CodeFirst.BulkInsert.MySql 5 | { 6 | public class MySqlBulkInsertTest : BulkInsertTestBase 7 | { 8 | protected override string ProviderConnectionType 9 | { 10 | get { return "MySql.Data.MySqlClient.MySqlConnection"; } 11 | } 12 | 13 | protected override MySqlContext GetContext() 14 | { 15 | return new MySqlContext(); 16 | } 17 | 18 | public override void MixedTransactionsCommit() 19 | { 20 | // MySql does not support Mixed Transactions, force pass here 21 | Assert.AreEqual(true, true); 22 | } 23 | 24 | public override void DbGeographyObject() 25 | { 26 | // MySql does not support geography spatial type, force pass 27 | Assert.AreEqual(true, true); 28 | } 29 | 30 | public override void BulkInsertWithIdentityInsertOn() 31 | { 32 | // MySql does support identity insert, however the MySql provider Migration class 33 | // creates a trigger that forces ALWAYS creates an identity value 34 | // look into contributing and submitting slightly modified trigger to allow for identity insert 35 | // https://www.electrictoolbox.com/mysql-guid-uuid-default-column/ 36 | base.BulkInsertWithIdentityInsertOn(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/BulkInsert/PerformanceTestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading; 4 | using EntityFramework.BulkInsert.Extensions; 5 | using EntityFramework.BulkInsert.Providers; 6 | using NUnit.Framework; 7 | 8 | namespace EntityFramework.BulkInsert.Test.CodeFirst.BulkInsert 9 | { 10 | [TestFixture] 11 | public abstract class PerformanceTestBase : TestBase 12 | where T : IEfBulkInsertProvider, new() 13 | where TContext : TestBaseContext, new() 14 | { 15 | public override void Setup() 16 | { 17 | ProviderFactory.Register(ProviderConnectionType); 18 | base.Setup(); 19 | } 20 | 21 | protected abstract string ProviderConnectionType { get; } 22 | 23 | /// 24 | /// 25 | /// 26 | /// 27 | private void BulkInsertPages(int pagesCount) 28 | { 29 | using (var ctx = GetContext()) 30 | { 31 | var pages = CreatePages(pagesCount); 32 | RunBulkInsert(ctx, pages, pagesCount); 33 | } 34 | } 35 | 36 | [Test] 37 | [Category("PerformanceTest")] 38 | public void Insert500kPagesInTwoThreads() 39 | { 40 | Console.WriteLine($"Provider: {ProviderConnectionType}"); 41 | 42 | var t = new Thread(() => BulkInsertPages(250000)); 43 | var t2 = new Thread(() => BulkInsertPages(250000)); 44 | 45 | var sw = new Stopwatch(); 46 | sw.Start(); 47 | t.Start(); 48 | t2.Start(); 49 | 50 | t.Join(); 51 | t2.Join(); 52 | sw.Stop(); 53 | Console.WriteLine("Total:{0}ms", sw.Elapsed.TotalMilliseconds); 54 | } 55 | 56 | [Test] 57 | [Category("PerformanceTest")] 58 | public void Insert500kPagesInFiveThreads() 59 | { 60 | Console.WriteLine($"Provider: {ProviderConnectionType}"); 61 | 62 | var t = new Thread(() => BulkInsertPages(100000)); 63 | var t2 = new Thread(() => BulkInsertPages(100000)); 64 | var t3 = new Thread(() => BulkInsertPages(100000)); 65 | var t4 = new Thread(() => BulkInsertPages(100000)); 66 | var t5 = new Thread(() => BulkInsertPages(100000)); 67 | 68 | var sw = new Stopwatch(); 69 | sw.Start(); 70 | t.Start(); 71 | t2.Start(); 72 | t3.Start(); 73 | t4.Start(); 74 | t5.Start(); 75 | 76 | t.Join(); 77 | t2.Join(); 78 | t3.Join(); 79 | t4.Join(); 80 | t5.Join(); 81 | sw.Stop(); 82 | 83 | Console.WriteLine("Total:{0}ms", sw.Elapsed.TotalMilliseconds); 84 | } 85 | 86 | [Test] 87 | [Category("PerformanceTest")] 88 | public void Insert500kPages() 89 | { 90 | Console.WriteLine($"Provider: {ProviderConnectionType}"); 91 | BulkInsertPages(500000); 92 | } 93 | 94 | [Test] 95 | [Category("PerformanceTest")] 96 | public void BulkInsertVsAddRange() 97 | { 98 | Console.WriteLine($"Provider: {ProviderConnectionType}"); 99 | var pagesCount = 1; 100 | for (int mul = 0; mul < 10; mul++) 101 | { 102 | double bulkinsert, addRange; 103 | 104 | using (var ctx = GetContext()) 105 | { 106 | var sw = new Stopwatch(); 107 | sw.Restart(); 108 | ctx.BulkInsert(CreatePages(pagesCount)); 109 | sw.Stop(); 110 | 111 | bulkinsert = sw.Elapsed.TotalMilliseconds; 112 | } 113 | 114 | using (var ctx = GetContext()) 115 | { 116 | var sw = new Stopwatch(); 117 | sw.Restart(); 118 | ctx.Pages.AddRange(CreatePages(pagesCount)); 119 | ctx.SaveChanges(); 120 | sw.Stop(); 121 | addRange = sw.Elapsed.TotalMilliseconds; 122 | } 123 | Console.WriteLine("{0}\t{1}\t{2}", pagesCount, bulkinsert, addRange); 124 | 125 | //Console.WriteLine("{0}\t{1}", pagesCount, bulkinsert); 126 | pagesCount += 10000; 127 | } 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/BulkInsert/SqlCe/SqlCeBulkInsertTest.cs: -------------------------------------------------------------------------------- 1 | #if SQLCE 2 | using System.Data.Entity; 3 | #if EF6 4 | using System.Data.Entity.Core.Common; 5 | using System.Data.Entity.SqlServerCompact; 6 | #endif 7 | #if EF5 8 | using System.Data.Common; 9 | #endif 10 | using System.Data.Entity.Infrastructure; 11 | using EntityFramework.BulkInsert.SqlServerCe; 12 | using EntityFramework.Bulkinsert.Test.CodeFirst; 13 | 14 | namespace EntityFramework.BulkInsert.Test.CodeFirst.BulkInsert.SqlCe 15 | { 16 | public class SqlCeBulkInsertTest : BulkInsertTestBase 17 | { 18 | private bool _loaded = false; 19 | 20 | public override void Setup() 21 | { 22 | #if EF6 23 | if (!_loaded) 24 | { 25 | DbConfiguration.Loaded += (_, a) => 26 | { 27 | a.ReplaceService((s, k) => SqlCeProviderServices.Instance); 28 | a.ReplaceService( 29 | (s, k) => new SqlCeConnectionFactory(SqlCeProviderServices.ProviderInvariantName)); 30 | }; 31 | _loaded = true; 32 | } 33 | #endif 34 | base.Setup(); 35 | } 36 | 37 | protected override SqlCeContext GetContext() 38 | { 39 | var context = new SqlCeContext("SqlCeContext"); 40 | context.Database.CreateIfNotExists(); 41 | return context; 42 | } 43 | 44 | public override void BulkInsertTableWithComputedColumns() 45 | { 46 | // not supported 47 | } 48 | 49 | #if NET45 50 | public override void DbGeographyObject() 51 | { 52 | // not supported 53 | } 54 | #endif 55 | 56 | #if EF6 57 | public override void Issue1344Test() 58 | { 59 | // not relavant 60 | } 61 | 62 | public override void Issue1369Test() 63 | { 64 | // not relavant 65 | } 66 | #endif 67 | protected override string ProviderConnectionType 68 | { 69 | get { return "System.Data.SqlServerCe.SqlCeConnection"; } 70 | } 71 | } 72 | } 73 | #endif -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/BulkInsert/SqlServer/SqlBulkInsertPerformanceTest.cs: -------------------------------------------------------------------------------- 1 | using EntityFramework.BulkInsert.Providers; 2 | 3 | namespace EntityFramework.BulkInsert.Test.CodeFirst.BulkInsert.SqlServer 4 | { 5 | public class SqlBulkInsertPerformanceTest : PerformanceTestBase 6 | { 7 | protected override string ProviderConnectionType 8 | { 9 | get { return "System.Data.SqlClient.SqlConnection"; } 10 | } 11 | 12 | protected override SqlContext GetContext() 13 | { 14 | return new SqlContext(); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/BulkInsert/SqlServer/SqlBulkInsertTest.cs: -------------------------------------------------------------------------------- 1 | using EntityFramework.BulkInsert.Providers; 2 | 3 | namespace EntityFramework.BulkInsert.Test.CodeFirst.BulkInsert.SqlServer 4 | { 5 | public class SqlBulkInsertTest : BulkInsertTestBase 6 | { 7 | protected override string ProviderConnectionType 8 | { 9 | get { return "System.Data.SqlClient.SqlConnection"; } 10 | } 11 | 12 | protected override SqlContext GetContext() 13 | { 14 | return new SqlContext(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/BulkInsert/SqlServer/SqlBulkInsertWithDataTable.cs: -------------------------------------------------------------------------------- 1 | using EntityFramework.BulkInsert.Providers; 2 | 3 | namespace EntityFramework.BulkInsert.Test.CodeFirst.BulkInsert.SqlServer 4 | { 5 | public class SqlBulkInsertWithDataTable : BulkInsertTestBase 6 | { 7 | protected override string ProviderConnectionType 8 | { 9 | get { return "System.Data.SqlClient.SqlConnection"; } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/BulkInsert/SqlServer/SqlBulkInsertWithDataTablePerformance.cs: -------------------------------------------------------------------------------- 1 | using EntityFramework.BulkInsert.Providers; 2 | 3 | namespace EntityFramework.BulkInsert.Test.CodeFirst.BulkInsert.SqlServer 4 | { 5 | public class SqlBulkInsertWithDataTablePerformance : PerformanceTestBase 6 | { 7 | protected override string ProviderConnectionType 8 | { 9 | get { return "System.Data.SqlClient.SqlConnection"; } 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/Company.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFramework.BulkInsert.Test.Domain 2 | { 3 | public class Company 4 | { 5 | public int CompanyId { get; set; } 6 | public string CompanyName { get; set; } 7 | public CompanySize Size { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/CompanySize.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFramework.BulkInsert.Test.Domain 2 | { 3 | public enum CompanySize 4 | { 5 | Small, 6 | Medium, 7 | Large, 8 | ExtraLarge 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/ComplexTypes/Address.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | namespace EntityFramework.BulkInsert.Test.Domain.ComplexTypes 4 | { 5 | public class Address 6 | { 7 | public string Country { get; set; } 8 | public string County { get; set; } 9 | public string City { get; set; } 10 | public string PostalCode { get; set; } 11 | public string StreetAddress { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/ComplexTypes/Contact.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFramework.BulkInsert.Test.Domain.ComplexTypes 2 | { 3 | public class Contact 4 | { 5 | public string PhoneNumber { get; set; } 6 | public Address Address { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/Contract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFramework.BulkInsert.Test.Domain 4 | { 5 | public abstract class ContractBase : Entity, ICreatedAt, IModifiedAt 6 | { 7 | public string ContractNr { get; set; } 8 | public string AvpContractNr { get; set; } 9 | 10 | public int MeteringPointId { get; set; } 11 | public virtual MeteringPoint MeteringPoint { get; set; } 12 | 13 | public DateTime StartDate { get; set; } 14 | 15 | public DateTime? EndDate { get; set; } 16 | 17 | public DateTime? ContractSignedAt { get; set; } 18 | 19 | /// 20 | /// Utc time of contract start date. Readonly 21 | /// 22 | public DateTime StartDateUtc { get; protected set; } 23 | 24 | /// 25 | /// Utc time of contract end date. Readonly 26 | /// 27 | public DateTime? EndDateUtc { get; protected set; } 28 | 29 | public int ClientId { get; set; } 30 | 31 | public decimal? FixedPrice { get; set; } 32 | 33 | public int? PackageId { get; set; } 34 | public string PackageName { get; set; } 35 | 36 | public bool Validated { get; set; } 37 | 38 | public DateTime CreatedAt { get; set; } 39 | public DateTime? ModifiedAt { get; set; } 40 | public DateTime? LastPricesCalculatedAt { get; set; } 41 | 42 | protected ContractBase() 43 | { 44 | StartDate = DateTime.Now; 45 | StartDateUtc = DateTime.Now; 46 | CreatedAt = DateTime.Now; 47 | } 48 | } 49 | 50 | public class Contract : ContractBase 51 | { 52 | 53 | } 54 | 55 | public class ContractFixed : ContractBase 56 | { 57 | public int PackageFixedId { get; set; } 58 | 59 | public string PricesJson { get; set; } 60 | } 61 | 62 | public class ContractStock : ContractBase 63 | { 64 | public decimal? Margin { get; set; } 65 | 66 | public int PackageStockId { get; set; } 67 | } 68 | 69 | public class ContractKomb1 : ContractBase 70 | { 71 | public int PackageKomb1Id { get; set; } 72 | 73 | public decimal Base { get; set; } 74 | public decimal? StockMargin { get; set; } 75 | public string FixPricesJson { get; set; } 76 | 77 | public int SubPackageId { get; set; } 78 | } 79 | 80 | public class ContractKomb2 : ContractBase 81 | { 82 | public int PackageKomb2Id { get; set; } 83 | 84 | public decimal? Part1Margin { get; set; } 85 | public string Part1PricesJson { get; set; } 86 | 87 | public int Part1SubPackageId { get; set; } 88 | 89 | public decimal? Part2Margin { get; set; } 90 | public string Part2PricesJson { get; set; } 91 | 92 | public int Part2SubPackageId { get; set; } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/Employee.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace EntityFramework.BulkInsert.Test.Domain 8 | { 9 | public abstract class EmployeeTPT 10 | { 11 | public int Id { get; set; } 12 | public string Name { get; set; } 13 | public string JobTitle { get; set; } 14 | } 15 | 16 | public class WorkerTPT : EmployeeTPT 17 | { 18 | 19 | public virtual ManagerTPT Boss { get; set; } 20 | } 21 | 22 | public class ManagerTPT : EmployeeTPT 23 | { 24 | public string Rank { get; set; } 25 | public virtual ICollection Henchmen { get; set; } 26 | } 27 | 28 | 29 | public abstract class EmployeeTPH 30 | { 31 | public string NameWithTitle { get { return string.Format("{0} ({1})", Name, Title); } } 32 | 33 | public int Id { get; set; } 34 | public string Name { get; set; } 35 | public string Title { get; set; } 36 | } 37 | 38 | public class AWorkerTPH : EmployeeTPH 39 | { 40 | public int BossId { get; set; } 41 | public int RefId { get; set; } 42 | public virtual ManagerTPH Boss { get; set; } 43 | } 44 | 45 | public class ManagerTPH : EmployeeTPH 46 | { 47 | public string Rank { get; set; } 48 | public int? RefId { get; set; } 49 | public virtual ICollection Henchmen { get; set; } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/Entity.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFramework.BulkInsert.Test.Domain 2 | { 3 | public abstract class Entity : EntityWithTypedId 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/EntityWithTypedId.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFramework.BulkInsert.Test.Domain 2 | { 3 | public abstract class EntityWithTypedId 4 | { 5 | public T Id { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/Foo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace EntityFramework.BulkInsert.Test.CodeFirst.Domain 8 | { 9 | public class Foo 10 | { 11 | public int Id { get; set; } 12 | public string Bar { get; set; } 13 | 14 | public int X { get; set; } 15 | public int Y { get; set; } 16 | public int Z { get; set; } 17 | } 18 | 19 | public class FooExtended : Foo 20 | { 21 | public string ExtendedValue { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/ICreatedAt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFramework.BulkInsert.Test.Domain 4 | { 5 | public interface ICreatedAt 6 | { 7 | DateTime CreatedAt { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/IModifiedAt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFramework.BulkInsert.Test.Domain 4 | { 5 | public interface IModifiedAt 6 | { 7 | DateTime? ModifiedAt { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/MeteringPoint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFramework.BulkInsert.Test.Domain 4 | { 5 | public class MeteringPoint : Entity, ICreatedAt, IModifiedAt 6 | { 7 | public string EIC { get; set; } 8 | 9 | public DateTime CreatedAt { get; set; } 10 | public DateTime? ModifiedAt { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/Page.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace EntityFramework.BulkInsert.Test.Domain 5 | { 6 | public class Page 7 | { 8 | 9 | public int PageId { get; set; } 10 | 11 | public string Content { get; set; } 12 | 13 | public string Title { get; set; } 14 | 15 | public int? ParentId { get; set; } 16 | 17 | public virtual Page Parent { get; set; } 18 | 19 | public virtual ICollection Translations { get; set; } 20 | 21 | public DateTime CreatedAt { get; set; } 22 | 23 | public DateTime? ModifiedAt { get; set; } 24 | } 25 | 26 | public class Item 27 | { 28 | public int Id { get; set; } 29 | public int X { get; set; } 30 | public int Y { get; set; } 31 | } 32 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/PageTranslations.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFramework.BulkInsert.Test.Domain 2 | { 3 | public class PageTranslations 4 | { 5 | public int PageId { get; set; } 6 | 7 | public virtual Page Page { get; set; } 8 | 9 | public string Language { get; set; } 10 | 11 | public string Title { get; set; } 12 | 13 | public string Content { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/PinPoint.cs: -------------------------------------------------------------------------------- 1 | #if NET45 2 | #if EF6 3 | using System.Data.Entity.Spatial; 4 | #endif 5 | #if EF5 6 | using System.Data.Spatial; 7 | #endif 8 | #endif 9 | 10 | namespace EntityFramework.BulkInsert.Test.Domain 11 | { 12 | public class PinPoint : Entity 13 | { 14 | public string Name { get; set; } 15 | 16 | #if NET45 17 | public DbGeography Coordinates { get; set; } 18 | #endif 19 | } 20 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/Reading.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFramework.BulkInsert.Test.Domain 4 | { 5 | public class Reading : Entity 6 | { 7 | public int MeteringPointId { get; set; } 8 | public virtual MeteringPoint MeteringPoint { get; set; } 9 | public DateTime Date { get; set; } 10 | public decimal? Consumed { get; set; } 11 | public decimal? Produced { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/Domain/TestUser.cs: -------------------------------------------------------------------------------- 1 | using EntityFramework.BulkInsert.Test.Domain.ComplexTypes; 2 | using System; 3 | 4 | namespace EntityFramework.BulkInsert.Test.Domain 5 | { 6 | public class TestUser : EntityWithTypedId 7 | { 8 | public Contact Contact { get; set; } 9 | public string FirstName { get; set; } 10 | public string LastName { get; set; } 11 | public string FullName { get { return string.Format("{0} {1}", FirstName, LastName); }} 12 | public DateTime CreatedAt { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/MySqlContext.cs: -------------------------------------------------------------------------------- 1 | using EntityFramework.BulkInsert.Test.Domain; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Data.Entity; 5 | #if EF6 6 | using System.Data.Entity.Infrastructure; 7 | #endif 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | 12 | namespace EntityFramework.BulkInsert.Test.CodeFirst 13 | { 14 | #if EF6 15 | [DbConfigurationType(typeof(MySqlContextConfig))] 16 | #endif 17 | public class MySqlContext : TestBaseContext 18 | { 19 | public MySqlContext() : base("MySqlTestContext") 20 | { 21 | 22 | } 23 | } 24 | 25 | #if EF6 26 | public class MySqlContextConfig : DbConfiguration 27 | { 28 | public MySqlContextConfig() 29 | { 30 | SetProviderServices( 31 | nameof(global::MySql.Data.MySqlClient), 32 | new global::MySql.Data.MySqlClient.MySqlProviderServices() 33 | ); 34 | 35 | SetExecutionStrategy(nameof(global::MySql.Data.MySqlClient), () => new DefaultExecutionStrategy()); 36 | } 37 | } 38 | #endif 39 | } 40 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/SqlCeContext.cs: -------------------------------------------------------------------------------- 1 | #if SQLCE 2 | #if EF6 3 | using System.Data.Entity; 4 | using System.Data.Entity.SqlServerCompact; 5 | #endif 6 | 7 | using EntityFramework.BulkInsert.Test.CodeFirst; 8 | 9 | namespace EntityFramework.Bulkinsert.Test.CodeFirst 10 | { 11 | #if EF6 12 | [DbConfigurationType(typeof (SqlCeConfig))] 13 | #endif 14 | public class SqlCeContext : TestBaseContext 15 | { 16 | public SqlCeContext() 17 | { 18 | } 19 | 20 | public SqlCeContext(string cs) 21 | : base(cs) 22 | { 23 | 24 | } 25 | } 26 | 27 | #if EF6 28 | public class SqlCeConfig : DbConfiguration 29 | { 30 | public SqlCeConfig() 31 | { 32 | SetProviderServices( 33 | SqlCeProviderServices.ProviderInvariantName, 34 | SqlCeProviderServices.Instance); 35 | } 36 | } 37 | #endif 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/SqlContext.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Entity; 2 | using EntityFramework.BulkInsert.Test.CodeFirst.Domain; 3 | using EntityFramework.BulkInsert.Test.Domain; 4 | #if EF6 5 | using System.Data.Entity.Infrastructure; 6 | #endif 7 | 8 | namespace EntityFramework.BulkInsert.Test.CodeFirst 9 | { 10 | #if EF6 11 | [DbConfigurationType(typeof(SqlContextConfig))] 12 | #endif 13 | public class SqlContext : TestBaseContext 14 | { 15 | #if NET45 16 | public DbSet PinPoints { get; set; } 17 | #endif 18 | } 19 | 20 | #if EF6 21 | public class SqlContextConfig : DbConfiguration 22 | { 23 | public SqlContextConfig() 24 | { 25 | SetExecutionStrategy("System.Data.SqlClient", () => new DefaultExecutionStrategy()); 26 | } 27 | } 28 | #endif 29 | } 30 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CodeFirst/TestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.Entity; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using Calculator.Data; 7 | using EntityFramework.BulkInsert.Extensions; 8 | using EntityFramework.BulkInsert.Test.Domain; 9 | using EntityFramework.BulkInsert.Test.Domain.ComplexTypes; 10 | using NUnit.Framework; 11 | 12 | namespace EntityFramework.BulkInsert.Test.CodeFirst 13 | { 14 | public abstract class TestBase where T : DbContext, new() 15 | { 16 | [SetUp] 17 | public virtual void Setup() 18 | { 19 | using (var ctx = GetContext()) 20 | { 21 | if (ctx.Database.Exists()) 22 | { 23 | Database.SetInitializer(null); 24 | } 25 | else 26 | { 27 | var sw = new Stopwatch(); 28 | sw.Start(); 29 | ctx.Database.Initialize(false); 30 | sw.Stop(); 31 | Console.WriteLine("Initializing dbmodel took: {0}ms", sw.Elapsed.TotalMilliseconds); 32 | } 33 | } 34 | } 35 | 36 | protected abstract T GetContext(); 37 | /* 38 | { 39 | T ctx = contextName == null 40 | ? new T() 41 | : (T)Activator.CreateInstance(typeof(T), contextName); 42 | 43 | ctx.Configuration.AutoDetectChangesEnabled = false; 44 | ctx.Configuration.LazyLoadingEnabled = false; 45 | ctx.Configuration.ProxyCreationEnabled = false; 46 | ctx.Configuration.ValidateOnSaveEnabled = false; 47 | 48 | return ctx; 49 | } 50 | */ 51 | 52 | protected static IEnumerable CreatePages(int count) 53 | { 54 | for (int i = 0; i < count; ++i) 55 | { 56 | yield return new Page { Title = "title" + i, Content = "content" + i, CreatedAt = DateTime.Now }; 57 | } 58 | } 59 | 60 | protected static IEnumerable CreateUsers(int count) 61 | { 62 | for (int i = 0; i < count; ++i) 63 | { 64 | yield return new TestUser 65 | { 66 | CreatedAt = DateTime.Now, 67 | FirstName = i + "fn", 68 | LastName = "ln" + i, 69 | Contact = new Contact { PhoneNumber = "123456", Address = new Address { City = "Tallinn", Country = "Estonia", County = "Harju", PostalCode = "-" } } 70 | }; 71 | } 72 | } 73 | 74 | protected static void RunBulkInsert(T ctx, IEnumerable users, int itemsCount) 75 | { 76 | var sw = new Stopwatch(); 77 | sw.Start(); 78 | ctx.BulkInsert(users); 79 | sw.Stop(); 80 | Console.WriteLine("Bulk insert with {0} items elapsed: {1}ms", itemsCount, TimeSpan.FromTicks(sw.ElapsedTicks).TotalMilliseconds); 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/CustomProvider/SqlCeTest.cs: -------------------------------------------------------------------------------- 1 | #if SQLCE 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Data; 5 | using System.Data.Entity; 6 | using System.Data.Entity.Migrations.Infrastructure; 7 | using System.Data.Entity.Migrations.Model; 8 | //using System.Data.Entity.SqlServerCompact; 9 | using System.Data.SqlClient; 10 | using System.Diagnostics; 11 | using System.Linq; 12 | using System.Text; 13 | using System.Threading.Tasks; 14 | using EntityFramework.BulkInsert.Extensions; 15 | using EntityFramework.BulkInsert.Providers; 16 | using EntityFramework.BulkInsert.SqlServerCe; 17 | using EntityFramework.BulkInsert.Test.CodeFirst; 18 | using EntityFramework.Bulkinsert.Test.CodeFirst; 19 | using EntityFramework.BulkInsert.Test.Domain; 20 | using EntityFramework.BulkInsert.Test.Domain.ComplexTypes; 21 | using ErikEJ.SqlCe; 22 | using NUnit.Framework; 23 | 24 | namespace EntityFramework.BulkInsert.Test.CustomProvider 25 | { 26 | [TestFixture] 27 | public class SqlCeTest : TestBase 28 | { 29 | [SetUp] 30 | public void SetUp() 31 | { 32 | ProviderFactory.Register("System.Data.SqlServerCe.SqlCeConnection"); 33 | } 34 | 35 | private IEnumerable Items(int count) 36 | { 37 | for (int i = 0; i < count; ++i) 38 | { 39 | yield return new Item {X = i, Y = count - i}; 40 | } 41 | } 42 | 43 | [Test] 44 | public void Test() 45 | { 46 | using (var ctx = new SqlCeContext("SqlCeContext")) 47 | { 48 | ctx.Database.Initialize(false); 49 | 50 | for (int i = 0; i < 1000; i++) 51 | { 52 | ctx.Pages.Add(new Page { Content = "pla", CreatedAt = DateTime.Now }); 53 | } 54 | ctx.SaveChanges(); 55 | 56 | var pagescount = ctx.Pages.Count(); 57 | Console.WriteLine(pagescount); 58 | } 59 | } 60 | 61 | [Test] 62 | public void Vs() 63 | { 64 | var sw = new Stopwatch(); 65 | sw.Start(); 66 | SqlCeBulkCopyOptions options = new SqlCeBulkCopyOptions(); 67 | using (SqlCeBulkCopy bc = new SqlCeBulkCopy("Data Source=|DataDirectory|Database1.sdf", options)) 68 | { 69 | bc.DestinationTableName = "Items"; 70 | bc.WriteToServer(Items(1000000), typeof(Item)); 71 | } 72 | sw.Stop(); 73 | Console.WriteLine("bulk insert elapsed {0}ms", sw.Elapsed.TotalMilliseconds); 74 | } 75 | 76 | [Test] 77 | public void BulkInsert() 78 | { 79 | using (var ctx = new SqlCeContext("SqlCeContext")) 80 | { 81 | var sw = new Stopwatch(); 82 | sw.Start(); 83 | ctx.Database.Initialize(false); 84 | ctx.BulkInsert(Items(1)); 85 | sw.Stop(); 86 | Console.WriteLine("initialized within {0}ms", sw.Elapsed.TotalMilliseconds); 87 | 88 | sw.Restart(); 89 | ctx.BulkInsert(Items(1000000)); 90 | sw.Stop(); 91 | Console.WriteLine("bulk insert elapsed {0}ms", sw.Elapsed.TotalMilliseconds); 92 | 93 | Console.WriteLine(ctx.Items.Count()); 94 | } 95 | } 96 | 97 | protected override SqlCeContext GetContext() 98 | { 99 | return new SqlCeContext("SqlCeContext"); 100 | } 101 | } 102 | } 103 | #endif -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DatabaseFirst/Authors.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace EntityFramework.BulkInsert.Test.DatabaseFirst 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class Authors 16 | { 17 | public Authors() 18 | { 19 | this.Books = new HashSet(); 20 | } 21 | 22 | public int Id { get; set; } 23 | public Nullable BirthDay { get; set; } 24 | public string Name { get; set; } 25 | public string MiddleName { get; set; } 26 | public string LastName { get; set; } 27 | 28 | public virtual ICollection Books { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DatabaseFirst/Books.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace EntityFramework.BulkInsert.Test.DatabaseFirst 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class Books 16 | { 17 | public Books() 18 | { 19 | this.Authors = new HashSet(); 20 | } 21 | 22 | public int Id { get; set; } 23 | public string ISBN10 { get; set; } 24 | public string ISBN13 { get; set; } 25 | public string Title { get; set; } 26 | public byte[] Cover { get; set; } 27 | public string Edition { get; set; } 28 | public int PublisherId { get; set; } 29 | public Nullable PublishedAt { get; set; } 30 | public System.DateTime ModifiedAt { get; set; } 31 | public System.DateTime CreatedAt { get; set; } 32 | 33 | public virtual Publishers Publishers { get; set; } 34 | public virtual ICollection Authors { get; set; } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DatabaseFirst/DatabaseFirstTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.Entity; 3 | using System.Linq; 4 | using EntityFramework.BulkInsert.Extensions; 5 | using EntityFramework.BulkInsert.Test.CodeFirst; 6 | using NUnit.Framework; 7 | 8 | namespace EntityFramework.BulkInsert.Test.DatabaseFirst 9 | { 10 | #if EF6 11 | [DbConfigurationType(typeof(SqlContextConfig))] 12 | #endif 13 | public partial class DbFirstTestEntities 14 | { 15 | 16 | } 17 | 18 | [TestFixture] 19 | public class Test 20 | { 21 | public DbFirstTestEntities GetContext() 22 | { 23 | return new DbFirstTestEntities(); 24 | } 25 | 26 | [Test] 27 | public void Insert() 28 | { 29 | using (var context = GetContext()) 30 | { 31 | var now = DateTime.Now; 32 | var g = Guid.NewGuid().ToString("N"); 33 | var books = new[] 34 | { 35 | new Books 36 | { 37 | CreatedAt = now, 38 | ISBN10 = "sfsfasdfsd", 39 | ISBN13 = "asdfasfd", 40 | Title = "Foo", 41 | ModifiedAt = now, 42 | Edition = g 43 | } 44 | }; 45 | 46 | context.BulkInsert(books); 47 | 48 | var lastBook = context.Books.OrderByDescending(x => x.CreatedAt).First(); 49 | 50 | Assert.AreEqual(g, lastBook.Edition); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DatabaseFirst/Publishers.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace EntityFramework.BulkInsert.Test.DatabaseFirst 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class Publishers 16 | { 17 | public Publishers() 18 | { 19 | this.Books = new HashSet(); 20 | } 21 | 22 | public int Id { get; set; } 23 | public string Name { get; set; } 24 | 25 | public virtual ICollection Books { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DatabaseFirst/TestDataModel.Context.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace EntityFramework.BulkInsert.Test.DatabaseFirst 11 | { 12 | using System; 13 | using System.Data.Entity; 14 | using System.Data.Entity.Infrastructure; 15 | 16 | public partial class DbFirstTestEntities : DbContext 17 | { 18 | public DbFirstTestEntities() 19 | : base("name=DbFirstTestEntities") 20 | { 21 | } 22 | 23 | protected override void OnModelCreating(DbModelBuilder modelBuilder) 24 | { 25 | throw new UnintentionalCodeFirstException(); 26 | } 27 | 28 | public virtual DbSet Authors { get; set; } 29 | public virtual DbSet Books { get; set; } 30 | public virtual DbSet Publishers { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DatabaseFirst/TestDataModel.Designer.cs: -------------------------------------------------------------------------------- 1 | // T4 code generation is enabled for model 'C:\code\EntityFramework.BulkInsert\src\EntityFramework.BulkInsert.Test\DatabaseFirst\TestDataModel.edmx'. 2 | // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer 3 | // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model 4 | // is open in the designer. 5 | 6 | // If no context and entity classes have been generated, it may be because you created an empty model but 7 | // have not yet chosen which version of Entity Framework to use. To generate a context class and entity 8 | // classes for your model, open the model in the designer, right-click on the designer surface, and 9 | // select 'Update Model from Database...', 'Generate Database from Model...', or 'Add Code Generation 10 | // Item...'. -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DatabaseFirst/TestDataModel.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DatabaseFirst/TestDataModel.edmx.diagram: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DbFirst/Blogs.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace EntityFramework.BulkInsert.Test.DbFirst 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class Blogs 16 | { 17 | public Blogs() 18 | { 19 | this.Posts = new HashSet(); 20 | } 21 | 22 | public int BlogId { get; set; } 23 | public string Name { get; set; } 24 | public string Url { get; set; } 25 | 26 | public virtual ICollection Posts { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DbFirst/BulkInsertTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using EntityFramework.BulkInsert.Extensions; 6 | using NUnit.Framework; 7 | 8 | namespace EntityFramework.BulkInsert.Test.DbFirst 9 | { 10 | public class BulkInsertTest : TestBase 11 | { 12 | [Test] 13 | public void InsertBlogs() 14 | { 15 | using (var ctx = GetContext()) 16 | { 17 | InitializeContext(); 18 | 19 | var blogs = new List(); 20 | for (int i = 0; i < 10000; ++i) 21 | { 22 | blogs.Add(new Blogs 23 | { 24 | Name = i + ". name", 25 | Url = i + ". url" 26 | }); 27 | } 28 | 29 | var sw = new Stopwatch(); 30 | sw.Start(); 31 | ctx.BulkInsert(blogs); 32 | sw.Stop(); 33 | Console.WriteLine("Bulk insert with {0} items elapsed: {1}ms", 10000, TimeSpan.FromTicks(sw.ElapsedTicks).TotalMilliseconds); 34 | } 35 | } 36 | 37 | private void InitializeContext() 38 | { 39 | using (var ctx = GetContext()) 40 | { 41 | var sw = new Stopwatch(); 42 | sw.Start(); 43 | var tmp = ctx.Blogs.Count(); 44 | sw.Stop(); 45 | Console.WriteLine("Initializing dbmodel took: {0}ms", sw.Elapsed.TotalMilliseconds); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DbFirst/DbFirstModel.Context.cs: -------------------------------------------------------------------------------- 1 | ErrorGeneratingOutput -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DbFirst/DbFirstModel.Designer.cs: -------------------------------------------------------------------------------- 1 | // Default code generation is disabled for model 'C:\dev\efBulkInsert\branches\ef6\Src\EntityFramework.BulkInsert.Test\DbFirst\DbFirstModel.edmx'. 2 | // To enable default code generation, change the value of the 'Code Generation Strategy' designer 3 | // property to an alternate value. This property is available in the Properties Window when the model is 4 | // open in the designer. -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DbFirst/DbFirstModel.cs: -------------------------------------------------------------------------------- 1 | ErrorGeneratingOutput -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DbFirst/DbFirstModel.edmx.diagram: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DbFirst/MappingTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using EntityFramework.BulkInsert.MappingAPI; 6 | using NUnit.Framework; 7 | 8 | namespace EntityFramework.BulkInsert.Test.DbFirst 9 | { 10 | [TestFixture] 11 | public class MappingTest : TestBase 12 | { 13 | [Test] 14 | public void TableNames() 15 | { 16 | using (var ctx = GetContext()) 17 | { 18 | var sw = new Stopwatch(); 19 | sw.Start(); 20 | var x = ctx.Blogs.FirstOrDefault(); 21 | sw.Stop(); 22 | Console.WriteLine("Initializing model took: {0}ms", sw.Elapsed.TotalMilliseconds); 23 | 24 | sw.Restart(); 25 | var dbmapping = EfMap.Get(ctx); 26 | sw.Start(); 27 | 28 | Console.WriteLine("Mapping took: {0}ms", sw.Elapsed.TotalMilliseconds); 29 | 30 | var tableMappings = dbmapping.Tables; 31 | 32 | foreach (var tableMapping in tableMappings) 33 | { 34 | Console.WriteLine("{0}: {1}", tableMapping.TypeFullName, tableMapping.TableName); 35 | } 36 | 37 | Assert.AreEqual(2, tableMappings.Length); 38 | 39 | AssertTableName(tableMappings, "Blogs"); 40 | AssertTableName(tableMappings, "Posts"); 41 | } 42 | } 43 | 44 | private void AssertTableName(IEnumerable tableMappings, string tableName) 45 | { 46 | Assert.True(tableMappings.Any(x => x.TableName == tableName && x.TypeFullName == typeof(T).FullName)); 47 | } 48 | 49 | private void AssertColumnName(IEnumerable columnMappings, string colName, string propName) 50 | { 51 | Console.WriteLine("prop: {0} > col: {1} (index: tbd)", propName, colName); 52 | var col = columnMappings.FirstOrDefault(x => x.ColumnName == colName && x.PropertyName == propName); 53 | Assert.IsNotNull(col); 54 | } 55 | 56 | [Test] 57 | public void ColumnNames_Blogs() 58 | { 59 | using (var ctx = GetContext()) 60 | { 61 | var tableMapping = EfMap.Get(ctx); 62 | 63 | var columns = tableMapping.Columns; 64 | Assert.AreEqual(3, columns.Length); 65 | 66 | AssertColumnName(columns, "BlogId", "BlogId"); 67 | AssertColumnName(columns, "Name", "Name"); 68 | AssertColumnName(columns, "Url", "Url"); 69 | } 70 | } 71 | 72 | [Test] 73 | public void ColumnNames_Posts() 74 | { 75 | using (var ctx = GetContext()) 76 | { 77 | var tableMapping = EfMap.Get(ctx); 78 | var columns = tableMapping.Columns; 79 | Assert.AreEqual(4, columns.Length); 80 | 81 | AssertColumnName(columns, "PostId", "PostId"); 82 | AssertColumnName(columns, "Title", "Title"); 83 | AssertColumnName(columns, "Content", "Content"); 84 | AssertColumnName(columns, "BlogId", "BlogId"); 85 | } 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DbFirst/Posts.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated from a template. 4 | // 5 | // Manual changes to this file may cause unexpected behavior in your application. 6 | // Manual changes to this file will be overwritten if the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace EntityFramework.BulkInsert.Test.DbFirst 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | 15 | public partial class Posts 16 | { 17 | public int PostId { get; set; } 18 | public string Title { get; set; } 19 | public string Content { get; set; } 20 | public int BlogId { get; set; } 21 | 22 | public virtual Blogs Blogs { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/DbFirst/TestBase.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Entity; 2 | using NUnit.Framework; 3 | 4 | namespace EntityFramework.BulkInsert.Test.DbFirst 5 | { 6 | [TestFixture] 7 | public class TestBase 8 | { 9 | [SetUp] 10 | public void Setup() 11 | { 12 | //Database.SetInitializer(new DropCreateDatabaseIfModelChanges()); 13 | //Database.SetInitializer(null); 14 | } 15 | 16 | protected DbFirstContext GetContext() 17 | { 18 | var ctx = new DbFirstContext(); 19 | 20 | ctx.Configuration.AutoDetectChangesEnabled = false; 21 | ctx.Configuration.LazyLoadingEnabled = false; 22 | ctx.Configuration.ProxyCreationEnabled = false; 23 | ctx.Configuration.ValidateOnSaveEnabled = false; 24 | 25 | return ctx; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/Issue1344/AccrualContext.cs: -------------------------------------------------------------------------------- 1 | #if EF6 2 | 3 | using System.Data.Entity; 4 | using Calculator.Data.Configurations; 5 | using Calculator.Entities; 6 | using DataAccess.EF.Conventions; 7 | 8 | namespace Calculator.Data 9 | { 10 | //[DbConfigurationType(typeof(EfDbConfiguration))] 11 | public class AccrualContext : DbContext 12 | { 13 | public DbSet Posts { get; set; } 14 | //public DbSet StandardDeductions { get; set; } 15 | 16 | public AccrualContext() 17 | : base("TestContext") 18 | { 19 | } 20 | 21 | protected override void OnModelCreating(DbModelBuilder modelBuilder) 22 | { 23 | modelBuilder.Conventions.Add(); 24 | modelBuilder.Configurations.Add(new PostConfiguration()); 25 | //modelBuilder.Configurations.Add(new StandardDeductionConfiguration()); 26 | } 27 | } 28 | } 29 | #endif 30 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/Issue1344/BaseXafConvention.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.Entity.ModelConfiguration.Conventions; 3 | 4 | namespace DataAccess.EF.Conventions 5 | { 6 | #if EF6 7 | public class BaseXafConvention : Convention 8 | { 9 | public BaseXafConvention() 10 | { 11 | Properties() 12 | .Where(p => p.Name == "Oid") 13 | .Configure(x => x.IsKey()); 14 | 15 | Properties() 16 | .Where(p => p.Name == "GcRecord") 17 | .Configure(x => x.HasColumnName("GCRecord")); 18 | 19 | Properties() 20 | .Configure(x => x.HasMaxLength(100)); 21 | } 22 | } 23 | #endif 24 | } 25 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/Issue1344/EfDbConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Entity; 2 | using System.Data.Entity.Infrastructure; 3 | using System.Data.Entity.SqlServer; 4 | 5 | namespace DataAccess.EF.Configurations 6 | { 7 | public class EfDbConfiguration : DbConfiguration 8 | { 9 | public EfDbConfiguration() 10 | { 11 | SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy()); 12 | SetDefaultConnectionFactory(new LocalDbConnectionFactory("v11.0")); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/Issue1344/IntervalEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DataAccess 4 | { 5 | public class IntervalEntity : XafGcEntity, IIntervalEntity 6 | { 7 | public Guid ResourceId { get; set; } 8 | public DateTime StartDate { get; set; } 9 | public DateTime EndDate { get; set; } 10 | } 11 | 12 | public interface IIntervalEntity : IResourceEntity 13 | { 14 | DateTime StartDate { get; set; } 15 | DateTime EndDate { get; set; } 16 | } 17 | 18 | public interface IResourceEntity : IEntity 19 | { 20 | T ResourceId { get; set; } 21 | } 22 | 23 | public interface IEntity 24 | { 25 | Guid Oid { get; set; } 26 | 27 | int? GcRecord { get; set; } 28 | } 29 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/Issue1344/Post.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DataAccess; 3 | 4 | namespace Calculator.Entities 5 | { 6 | public class Post : IntervalEntity 7 | { 8 | public Guid? WageTypeId { get; set; } 9 | public Guid? SubdivisionId { get; set; } 10 | public Guid? JobCategoryId { get; set; } 11 | public int CalculationMonth { get; set; } 12 | public int CalculationYear { get; set; } 13 | public int ActivityMonth { get; set; } 14 | public int ActivityYear { get; set; } 15 | public decimal PlannedDays { get; set; } 16 | public decimal PlannedHours { get; set; } 17 | public decimal WorkedDays { get; set; } 18 | public decimal WorkedHours { get; set; } 19 | public decimal AppliedPercentage { get; set; } 20 | public decimal Amount { get; set; } 21 | public int PaymentMonth { get; set; } 22 | public int PaymentYear { get; set; } 23 | public Guid? TaxDeductionTypeId { get; set; } 24 | public decimal TaxDeductionAmount { get; set; } 25 | public decimal AppliedTaxDeductionPercentage { get; set; } 26 | } 27 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/Issue1344/PostConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Entity.ModelConfiguration; 2 | using Calculator.Entities; 3 | 4 | namespace Calculator.Data.Configurations 5 | { 6 | public class PostConfiguration : EntityTypeConfiguration 7 | { 8 | public PostConfiguration() 9 | { 10 | ToTable("Accrual"); 11 | 12 | Property(p => p.ResourceId) 13 | .HasColumnName("PersonalAccount"); 14 | 15 | Property(p => p.StartDate) 16 | .HasColumnName("DateFrom"); 17 | 18 | Property(p => p.EndDate) 19 | .HasColumnName("DateTo"); 20 | 21 | Property(p => p.WageTypeId) 22 | .HasColumnName("Surcharges"); 23 | 24 | Property(p => p.SubdivisionId) 25 | .HasColumnName("CostDepartment"); 26 | 27 | Property(p => p.JobCategoryId) 28 | .HasColumnName("Category"); 29 | 30 | Property(p => p.CalculationMonth) 31 | .HasColumnName("MonthInWhichTheAccrued"); 32 | 33 | Property(p => p.CalculationYear) 34 | .HasColumnName("YearInWhichTheAccrued"); 35 | 36 | Property(p => p.ActivityMonth) 37 | .HasColumnName("MonthForWhichAccrued"); 38 | 39 | Property(p => p.ActivityYear) 40 | .HasColumnName("YearForWhichAccrued"); 41 | 42 | Property(p => p.PlannedDays) 43 | .HasColumnName("DaysGr"); 44 | 45 | Property(p => p.PlannedHours) 46 | .HasColumnName("HoursGr"); 47 | 48 | Property(p => p.WorkedDays) 49 | .HasColumnName("DaysFact"); 50 | 51 | Property(p => p.WorkedHours) 52 | .HasColumnName("HoursFact"); 53 | 54 | Property(p => p.AppliedPercentage) 55 | .HasColumnName("Percent"); 56 | 57 | Property(p => p.Amount) 58 | .HasColumnName("Amount"); 59 | 60 | Property(p => p.PaymentMonth) 61 | .HasColumnName("MonthInWhichPaid"); 62 | 63 | Property(p => p.PaymentYear) 64 | .HasColumnName("YearInWhichPaid"); 65 | 66 | Property(p => p.TaxDeductionTypeId) 67 | .HasColumnName("Deduction"); 68 | 69 | Property(p => p.TaxDeductionAmount) 70 | .HasColumnName("DeductionSumma"); 71 | 72 | Property(p => p.AppliedTaxDeductionPercentage) 73 | .HasColumnName("DeductionPercent"); 74 | } 75 | 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/Issue1344/Table Schema.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/src/EntityFramework.BulkInsert.Test/Issue1344/Table Schema.jpg -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/Issue1344/XafEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DataAccess 4 | { 5 | public class XafEntity 6 | { 7 | public Guid Oid { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/Issue1344/XafGcEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DataAccess 8 | { 9 | public class XafGcEntity : XafEntity 10 | { 11 | public int? GcRecord { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/Issue1369/Issue1369Context.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.Entity; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Aske.Persistence.Entities 9 | { 10 | public class Issue1369Context : DbContext 11 | { 12 | public DbSet Loans { get; set; } 13 | public DbSet CreditReports { get; set; } 14 | 15 | public Issue1369Context() 16 | : base("Issue1369Context") 17 | { 18 | } 19 | 20 | protected override void OnModelCreating(DbModelBuilder modelBuilder) 21 | { 22 | modelBuilder.Configurations.Add(new LoanConfig()); 23 | modelBuilder.Configurations.Add(new CreditReportConfig()); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("EntityFramework.BulkInsert.Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("EntityFramework.BulkInsert.Test")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("888191ea-1c28-486c-8aaa-089ae49eba73")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/BulkCopyOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFramework.BulkInsert 4 | { 5 | [Flags] 6 | public enum BulkCopyOptions 7 | { 8 | // 9 | // Summary: 10 | // Use the default values for all options. 11 | Default = 0, 12 | // 13 | // Summary: 14 | // Preserve source identity values. When not specified, identity values are assigned 15 | // by the destination. 16 | KeepIdentity = 1, 17 | // 18 | // Summary: 19 | // Check constraints while data is being inserted. By default, constraints are not 20 | // checked. 21 | CheckConstraints = 2, 22 | // 23 | // Summary: 24 | // Obtain a bulk update lock for the duration of the bulk copy operation. When not 25 | // specified, row locks are used. 26 | TableLock = 4, 27 | // 28 | // Summary: 29 | // Preserve null values in the destination table regardless of the settings for 30 | // default values. When not specified, null values are replaced by default values 31 | // where applicable. 32 | KeepNulls = 8, 33 | // 34 | // Summary: 35 | // When specified, cause the server to fire the insert triggers for the rows being 36 | // inserted into the database. 37 | FireTriggers = 16, 38 | // 39 | // Summary: 40 | // When specified, each batch of the bulk-copy operation will occur within a transaction. 41 | // If you indicate this option and also provide a System.Data.SqlClient.SqlTransaction 42 | // object to the constructor, an System.ArgumentException occurs. 43 | UseInternalTransaction = 32 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/BulkInsertDefaults.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFramework.BulkInsert 2 | { 3 | public static class BulkInsertDefaults 4 | { 5 | public static int BatchSize = 5000; 6 | public static BulkCopyOptions BulkCopyOptions = BulkCopyOptions.Default; 7 | public static int TimeOut = 30; 8 | public static int NotifyAfter = 1000; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/BulkInsertOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | 3 | namespace EntityFramework.BulkInsert 4 | { 5 | public class BulkInsertOptions 6 | { 7 | /// 8 | /// Batch size for bulk inserts. 9 | /// 10 | public int BatchSize { get; set; } 11 | 12 | /// 13 | /// Bulk copy options. 14 | /// 15 | public BulkCopyOptions BulkCopyOptions { get; set; } 16 | 17 | /// 18 | /// Number of the seconds for the operation to complete before it times out 19 | /// 20 | public int TimeOut { get; set; } 21 | 22 | /// 23 | /// Callback event handler. Event is fired after n (value from NotifyAfter) rows have been copied to table where. 24 | /// 25 | public RowsCopiedEventHandler Callback { get; set; } 26 | 27 | /// 28 | /// Used with property Callback. Sets number of rows after callback is fired. 29 | /// 30 | public int NotifyAfter { get; set; } 31 | 32 | /// 33 | /// If we already have a connection, use it instead of creating a new one. 34 | /// 35 | public IDbConnection Connection { get; set; } 36 | 37 | /// 38 | /// If we already have a transaction, use it instead of creating a new one. 39 | /// 40 | public IDbTransaction Transaction { get; set; } 41 | 42 | #if !NET40 43 | /// 44 | /// Enable streaming. 45 | /// 46 | public bool EnableStreaming { get; set; } 47 | #endif 48 | 49 | public BulkInsertOptions() 50 | { 51 | BatchSize = BulkInsertDefaults.BatchSize; 52 | BulkCopyOptions = BulkInsertDefaults.BulkCopyOptions; 53 | TimeOut = BulkInsertDefaults.TimeOut; 54 | NotifyAfter = BulkInsertDefaults.NotifyAfter; 55 | Connection = null; 56 | Transaction = null; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/Exceptions/BulkInsertProviderNotFoundException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFramework.BulkInsert.Exceptions 4 | { 5 | public class BulkInsertProviderNotFoundException : Exception 6 | { 7 | private readonly string _connectionType; 8 | public BulkInsertProviderNotFoundException(string connectionType) 9 | { 10 | _connectionType = connectionType; 11 | } 12 | 13 | public override string Message 14 | { 15 | get 16 | { 17 | return 18 | string.Format( 19 | "BulkInsertProvider not found for '{0}.\nTo register new provider use EntityFramework.BulkInsert.ProviderFactory.Register() method'", 20 | _connectionType); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/Exceptions/EntityTypeNotFoundException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFramework.BulkInsert.Exceptions 4 | { 5 | public class EntityTypeNotFoundException : Exception 6 | { 7 | private readonly Type _type; 8 | public EntityTypeNotFoundException(Type type) 9 | { 10 | _type = type; 11 | } 12 | 13 | public override string Message 14 | { 15 | get { return string.Format("Type '{0}' was not found in context", _type); } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/Extensions/DbContextExtensions.cs: -------------------------------------------------------------------------------- 1 | #if EF6 2 | 3 | using System; 4 | using System.Data.Entity; 5 | using System.Linq.Expressions; 6 | 7 | namespace EntityFramework.BulkInsert.Extensions 8 | { 9 | public static class DbContextExtensions 10 | { 11 | private static Delegate originalConnectionStringDelegate; 12 | private static readonly object syncLock; 13 | 14 | static DbContextExtensions() 15 | { 16 | syncLock = new object(); 17 | } 18 | 19 | public static string GetOriginalConnectionString(this DbContext dbContext) 20 | { 21 | object internalContext = dbContext.GetFieldValue("_internalContext"); 22 | 23 | if (originalConnectionStringDelegate == null) 24 | InitOriginalConnectionStringDelegate(internalContext.GetType()); 25 | 26 | return (string)originalConnectionStringDelegate.DynamicInvoke(internalContext); 27 | } 28 | 29 | private static void InitOriginalConnectionStringDelegate(Type internalContextType) 30 | { 31 | if (originalConnectionStringDelegate == null) 32 | { 33 | lock (syncLock) 34 | { 35 | if (originalConnectionStringDelegate == null) 36 | { 37 | Type lambdaType = typeof(Func<,>).MakeGenericType(internalContextType, typeof(string)); 38 | ParameterExpression param = Expression.Parameter(internalContextType, "arg"); 39 | MemberExpression member = Expression.PropertyOrField(param, "OriginalConnectionString"); 40 | LambdaExpression lambda = Expression.Lambda(lambdaType, member, param); 41 | 42 | originalConnectionStringDelegate = lambda.Compile(); 43 | } 44 | } 45 | } 46 | } 47 | } 48 | } 49 | #endif -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("EntityFramework.BulkInsert")] 9 | [assembly: AssemblyDescription("Fast bulk insert extension for Entity Framework")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("EntityFramework.BulkInsert")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | [assembly: InternalsVisibleTo("EntityFramework.BulkInsert.SqlServerCe")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f725b882-14a8-49d4-be87-32bcf09ddf61")] 24 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/ProviderFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.Entity; 4 | using EntityFramework.BulkInsert.Exceptions; 5 | using EntityFramework.BulkInsert.Providers; 6 | 7 | namespace EntityFramework.BulkInsert 8 | { 9 | public class ProviderFactory 10 | { 11 | private static Dictionary> _providers; 12 | 13 | private static readonly object providerInitializerLockObject = new object(); 14 | 15 | /// 16 | /// Registered bulkinsert providers container 17 | /// 18 | private static Dictionary> Providers 19 | { 20 | get 21 | { 22 | lock (providerInitializerLockObject) 23 | { 24 | if (_providers == null) 25 | { 26 | _providers = new Dictionary>(); 27 | 28 | // bundled providers 29 | Register(); 30 | } 31 | } 32 | 33 | return _providers; 34 | } 35 | } 36 | 37 | /// 38 | /// Register new bulkinsert provider. 39 | /// Rplaces existing if name matches. 40 | /// 41 | /// 42 | /// 43 | public static void Register(string name) 44 | where T : IEfBulkInsertProvider, new() 45 | { 46 | Providers[name] = () => new T(); 47 | } 48 | 49 | /// 50 | /// Register new bulk insert provider. 51 | /// 52 | /// 53 | public static void Register() 54 | where T : IEfBulkInsertProvider, new() 55 | { 56 | var instance = new T(); 57 | Providers[instance.ProviderIdentifier] = () => new T(); 58 | } 59 | 60 | /// 61 | /// Get bulkinsert porvider by connection used in context 62 | /// 63 | /// 64 | /// 65 | public static IEfBulkInsertProvider Get(DbContext context) 66 | { 67 | var connectionTypeName = context.Database.Connection.GetType().FullName; 68 | if (!Providers.ContainsKey(connectionTypeName)) 69 | { 70 | throw new BulkInsertProviderNotFoundException(connectionTypeName); 71 | } 72 | 73 | return Providers[connectionTypeName]().SetContext(context); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/Providers/EfSqlBulkInsertProviderWithDataTable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Data; 3 | using System.Data.SqlClient; 4 | using System.Linq; 5 | using EntityFramework.BulkInsert.Extensions; 6 | using EntityFramework.BulkInsert.Helpers; 7 | using EntityFramework.MappingAPI; 8 | using EntityFramework.MappingAPI.Extensions; 9 | 10 | namespace EntityFramework.BulkInsert.Providers 11 | { 12 | public class EfSqlBulkInsertProviderWithDataTable : ProviderBase 13 | { 14 | /* 15 | public override void Run(IEnumerable entities, BulkInsertOptions options) 16 | { 17 | var baseType = typeof(T); 18 | var allTypes = baseType.GetDerivedTypes(true); 19 | 20 | var neededMappings = allTypes.ToDictionary(x => x, x => EfMap.Get(Context)[x]); 21 | 22 | using (var dataTable = DataTableHelper.Create(neededMappings, entities)) 23 | { 24 | using (var sqlBulkCopy = new SqlBulkCopy(transaction.Connection, options.SqlBulkCopyOptionsValue, transaction)) 25 | { 26 | sqlBulkCopy.BatchSize = options.BatchSizeValue; 27 | sqlBulkCopy.BulkCopyTimeout = options.TimeOutValue; 28 | if (options.CallbackMethod != null) 29 | { 30 | sqlBulkCopy.NotifyAfter = options.NotifyAfterValue; 31 | sqlBulkCopy.SqlRowsCopied += options.CallbackMethod; 32 | } 33 | 34 | sqlBulkCopy.DestinationTableName = dataTable.TableName; 35 | #if !NET40 36 | sqlBulkCopy.EnableStreaming = options.EnableStreamingValue; 37 | #endif 38 | foreach (DataColumn col in dataTable.Columns) 39 | { 40 | sqlBulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName); 41 | } 42 | 43 | sqlBulkCopy.WriteToServer(dataTable); 44 | } 45 | } 46 | } 47 | */ 48 | 49 | public override void Run(IEnumerable entities, SqlTransaction transaction, BulkInsertOptions options) 50 | { 51 | var baseType = typeof (T); 52 | var allTypes = baseType.GetDerivedTypes(true); 53 | 54 | var neededMappings = allTypes.ToDictionary(x => x, x => Context.Db(x)); 55 | 56 | using (var dataTable = DataTableHelper.Create(neededMappings, entities)) 57 | { 58 | using (var sqlBulkCopy = new SqlBulkCopy(transaction.Connection, options.SqlBulkCopyOptions, transaction)) 59 | { 60 | sqlBulkCopy.BatchSize = options.BatchSize; 61 | sqlBulkCopy.DestinationTableName = dataTable.TableName; 62 | #if !NET40 63 | sqlBulkCopy.EnableStreaming = options.EnableStreaming; 64 | #endif 65 | 66 | foreach (DataColumn col in dataTable.Columns) 67 | { 68 | sqlBulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName); 69 | } 70 | 71 | sqlBulkCopy.WriteToServer(dataTable); 72 | 73 | /* 74 | // if there are any reference objects 75 | if (tableMapping.Relations.Length > 0) 76 | { 77 | // can be done only with identity columns 78 | var identityColumn = tableMapping.Columns.FirstOrDefault(x => x.IsIdentity); 79 | if (identityColumn != null) 80 | { 81 | var command = transaction.Connection.CreateCommand(); 82 | command.CommandText = "SELECT max(" + identityColumn.ColumnName + ") from " + dataTable.TableName; 83 | command.Transaction = transaction; 84 | 85 | var res = command.ExecuteScalar(); 86 | var lastId = long.Parse(res.ToString()); 87 | var firstId = lastId - dataTable.Rows.Count + 1; 88 | 89 | 90 | 91 | } 92 | } 93 | */ 94 | } 95 | } 96 | } 97 | 98 | protected override SqlConnection CreateConnection() 99 | { 100 | return new SqlConnection(ConnectionString); 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/Providers/IEfBulkInsertProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Data; 3 | using System.Data.Entity; 4 | using System.Threading.Tasks; 5 | using EntityFramework.BulkInsert.Extensions; 6 | 7 | namespace EntityFramework.BulkInsert.Providers 8 | { 9 | public interface IEfBulkInsertProvider 10 | { 11 | /// 12 | /// Gets a connection from the provider. 13 | /// 14 | /// 15 | IDbConnection GetConnection(); 16 | 17 | /// 18 | /// Executes a bulk insert command from the provider. 19 | /// 20 | /// Entity type. 21 | /// Entities to insert. 22 | void Run(IEnumerable entities); 23 | 24 | /// 25 | /// Executes a bulk insert command with a transaction from the provider. 26 | /// 27 | /// Entity type. 28 | /// Entities to insert. 29 | /// Transaction to use for the insert. 30 | void Run(IEnumerable entities, IDbTransaction transaction); 31 | 32 | /// 33 | /// Sets the database context. 34 | /// 35 | /// DbContext to set. 36 | /// 37 | IEfBulkInsertProvider SetContext(DbContext context); 38 | 39 | /// 40 | /// Sets the provider invariant name. 41 | /// 42 | /// 43 | void SetProviderIdentifier(string providerInvariantName); 44 | 45 | #if NET45 46 | 47 | /// 48 | /// 49 | /// 50 | /// 51 | /// 52 | /// 53 | Task RunAsync(IEnumerable entities); 54 | 55 | /// 56 | /// 57 | /// 58 | /// 59 | /// 60 | /// 61 | /// 62 | Task RunAsync(IEnumerable entities, IDbTransaction transaction); 63 | 64 | /// 65 | /// Get sql grography object from well known text 66 | /// 67 | /// Well known text representation of the value 68 | /// The identifier associated with the coordinate system. 69 | /// 70 | object GetSqlGeography(string wkt, int srid); 71 | 72 | /// 73 | /// Get sql geometry object from well known text 74 | /// 75 | /// Well known text representation of the value 76 | /// The identifier associated with the coordinate system. 77 | /// 78 | object GetSqlGeometry(string wkt, int srid); 79 | 80 | #endif 81 | 82 | /// 83 | /// Current DbContext. 84 | /// 85 | DbContext Context { get; } 86 | 87 | /// 88 | /// Bulk insert options. 89 | /// 90 | BulkInsertOptions Options { get; set; } 91 | 92 | /// 93 | /// The provider identifier. 94 | /// 95 | string ProviderIdentifier { get; } 96 | } 97 | } -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/RowsCopiedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFramework.BulkInsert 4 | { 5 | public class RowsCopiedEventArgs : EventArgs 6 | { 7 | public RowsCopiedEventArgs(long rowsCopied) 8 | { 9 | this.RowsCopied = rowsCopied; 10 | } 11 | 12 | //public bool Abort { get; set; } 13 | public long RowsCopied { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/RowsCopiedEventHandler.cs: -------------------------------------------------------------------------------- 1 | namespace EntityFramework.BulkInsert 2 | { 3 | public delegate void RowsCopiedEventHandler(object sender, RowsCopiedEventArgs args); 4 | } 5 | -------------------------------------------------------------------------------- /src/EntityFramework.BulkInsert/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/EfMap.cs: -------------------------------------------------------------------------------- 1 | using EntityFramework.MappingAPI.Mappings; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Data.Entity; 5 | using System.Data.Entity.Infrastructure; 6 | 7 | namespace EntityFramework.MappingAPI 8 | { 9 | /// 10 | /// 11 | /// 12 | internal class EfMap 13 | { 14 | /// 15 | /// 16 | /// 17 | private static readonly Dictionary Mappings = new Dictionary(); 18 | 19 | /// 20 | /// 21 | /// 22 | /// 23 | /// 24 | /// 25 | public static IEntityMap Get(DbContext context) 26 | { 27 | return (IEntityMap)Get(context)[typeof(T)]; 28 | } 29 | 30 | /// 31 | /// 32 | /// 33 | /// 34 | public static IEntityMap Get(DbContext context, Type type) 35 | { 36 | return Get(context)[type]; 37 | } 38 | 39 | /// 40 | /// 41 | /// 42 | /// 43 | public static IEntityMap Get(DbContext context, string typeFullName) 44 | { 45 | return Get(context)[typeFullName]; 46 | } 47 | 48 | /// 49 | /// 50 | /// 51 | /// 52 | /// 53 | public static DbMapping Get(DbContext context) 54 | { 55 | var cacheKey = context.GetType().FullName; 56 | 57 | var iDbModelCacheKeyProvider = context as IDbModelCacheKeyProvider; 58 | if (iDbModelCacheKeyProvider != null) 59 | { 60 | cacheKey = iDbModelCacheKeyProvider.CacheKey; 61 | } 62 | 63 | DbMapping mapping; 64 | if (Mappings.TryGetValue(cacheKey, out mapping)) 65 | return mapping; 66 | 67 | mapping = new DbMapping(context); 68 | 69 | Mappings[cacheKey] = mapping; 70 | return mapping; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/EntityFramework.MappingAPI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {9AEB6EB0-F898-43CF-B894-BD8E52428E7C} 8 | Library 9 | Properties 10 | EntityFramework.MappingAPI 11 | EntityFramework.MappingAPI 12 | v4.5 13 | 512 14 | true 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll 36 | 37 | 38 | ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/Exceptions/ParentNotMappedYetException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFramework.MappingAPI.Exceptions 4 | { 5 | public class ParentNotMappedYetException : Exception 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/Extensions/MappingApiExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.Entity; 3 | using System.Linq.Expressions; 4 | 5 | namespace EntityFramework.MappingAPI.Extensions 6 | { 7 | public static class MappingApiExtensions 8 | { 9 | /// 10 | /// 11 | /// 12 | /// 13 | /// 14 | public static IEntityMap[] Db(this DbContext ctx) 15 | { 16 | return EfMap.Get(ctx).Tables; 17 | } 18 | 19 | /// 20 | /// 21 | /// 22 | /// 23 | /// 24 | /// 25 | public static IEntityMap Db(this DbContext ctx) 26 | { 27 | return EfMap.Get(ctx); 28 | } 29 | 30 | /// 31 | /// 32 | /// 33 | /// 34 | /// 35 | /// 36 | /// 37 | /// 38 | public static IEntityMap Db(this T ctx, Expression>> dbset) where T : DbContext where T1 : class 39 | { 40 | return ctx.Db(); 41 | } 42 | 43 | /// 44 | /// 45 | /// 46 | /// 47 | /// 48 | /// 49 | public static IEntityMap Db(this DbContext ctx, Type type) 50 | { 51 | return EfMap.Get(ctx)[type]; 52 | } 53 | 54 | /// 55 | /// 56 | /// 57 | /// 58 | /// 59 | /// 60 | public static IEntityMap Db(this DbContext ctx, string typeFullName) 61 | { 62 | return EfMap.Get(ctx)[typeFullName]; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/IEntityMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFramework.MappingAPI 4 | { 5 | public interface IEntityMap 6 | { 7 | /// 8 | /// Entity type 9 | /// 10 | Type Type { get; } 11 | 12 | /// 13 | /// Table name in database 14 | /// 15 | string TableName { get; } 16 | 17 | /// 18 | /// Table schema 19 | /// 20 | string Schema { get; } 21 | 22 | /// 23 | /// Is table-per-hierarchy mapping 24 | /// 25 | bool IsTph { get; } 26 | 27 | /// 28 | /// Is table-per-hierarchy base entity 29 | /// 30 | bool IsRoot { get; } 31 | 32 | /// 33 | /// Mapped properties 34 | /// 35 | IPropertyMap[] Properties { get; } 36 | 37 | /// 38 | /// Foreign key properties 39 | /// 40 | IPropertyMap[] Fks { get; } 41 | 42 | /// 43 | /// Primary key properties 44 | /// 45 | IPropertyMap[] Pks { get; } 46 | 47 | /// 48 | /// Tph entity discriminators 49 | /// 50 | IPropertyMap[] Discriminators { get; } 51 | 52 | /// 53 | /// Gets property map by property name 54 | /// 55 | /// 56 | /// 57 | IPropertyMap this[string property] { get; } 58 | 59 | /// 60 | /// Gets property map by property name 61 | /// 62 | /// 63 | /// 64 | IPropertyMap Prop(string propertyName); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/IEntityMap`1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace EntityFramework.MappingAPI 5 | { 6 | /// 7 | /// Generic entity map 8 | /// 9 | /// Entity type 10 | public interface IEntityMap : IEntityMap 11 | { 12 | /// 13 | /// Get property mapping by predicate 14 | /// 15 | /// 16 | /// 17 | /// 18 | IPropertyMap Prop(Expression> predicate); 19 | } 20 | } -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/IPropertyMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using EntityFramework.MappingAPI.Mappings; 3 | 4 | namespace EntityFramework.MappingAPI 5 | { 6 | public interface IPropertyMap 7 | { 8 | /// 9 | /// Table column name property is mapped to 10 | /// 11 | string ColumnName { get; } 12 | 13 | /// 14 | /// Entity property name 15 | /// 16 | string PropertyName { get; } 17 | 18 | /// 19 | /// Is column primary key 20 | /// 21 | bool IsPk { get; } 22 | 23 | /// 24 | /// Is column nullable 25 | /// 26 | bool IsRequired { get; } 27 | 28 | /// 29 | /// Column default value 30 | /// 31 | object DefaultValue { get; } 32 | 33 | /// 34 | /// 35 | /// 36 | bool IsIdentity { get; } 37 | 38 | /// 39 | /// 40 | /// 41 | bool Computed { get; } 42 | 43 | /// 44 | /// Column max length 45 | /// 46 | int MaxLength { get; } 47 | 48 | /// 49 | /// Data type stored in the column 50 | /// 51 | Type Type { get; } 52 | 53 | /// 54 | /// Is table-per-hierarchy discriminator 55 | /// 56 | bool IsDiscriminator { get; } 57 | 58 | /// 59 | /// 60 | /// 61 | byte Precision { get; } 62 | 63 | /// 64 | /// 65 | /// 66 | byte Scale { get; } 67 | 68 | /// 69 | /// 70 | /// 71 | bool Unicode { get; } 72 | 73 | /// 74 | /// 75 | /// 76 | bool FixedLength { get; } 77 | 78 | /// 79 | /// Paren entity mapping 80 | /// 81 | IEntityMap EntityMap { get; } 82 | 83 | /// 84 | /// 85 | /// 86 | Delegate Selector { get; } 87 | 88 | #region nav property 89 | 90 | /// 91 | /// Is navigation property 92 | /// 93 | bool IsNavigationProperty { get; } 94 | 95 | /// 96 | /// Foreign key property name which is used for navigation property. 97 | /// 98 | string ForeignKeyPropertyName { get; } 99 | 100 | /// 101 | /// Foreign key property. 102 | /// Available only for navigation properties. 103 | /// 104 | IPropertyMap ForeignKey { get; } 105 | 106 | #endregion 107 | 108 | #region fk property 109 | 110 | /// 111 | /// Is foreign key 112 | /// 113 | bool IsFk { get; } 114 | 115 | /// 116 | /// Foreign keys navigation propery name 117 | /// 118 | string NavigationPropertyName { get; } 119 | 120 | /// 121 | /// Foreign key target column 122 | /// 123 | IPropertyMap FkTargetColumn { get; } 124 | 125 | /// 126 | /// Foreign key navigation property 127 | /// 128 | IPropertyMap NavigationProperty { get; } 129 | 130 | /// 131 | /// 132 | /// 133 | int? SRID { get; } 134 | 135 | /// 136 | /// 137 | /// 138 | bool IsStrict { get; } 139 | 140 | #endregion 141 | } 142 | } -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/Mappers/CodeFirstMapper.cs: -------------------------------------------------------------------------------- 1 | using EntityFramework.MappingAPI.Exceptions; 2 | using System.Data.Entity.Core.Metadata.Edm; 3 | using System.Linq; 4 | 5 | namespace EntityFramework.MappingAPI.Mappers 6 | { 7 | internal class CodeFirstMapper : MapperBase 8 | { 9 | public CodeFirstMapper(MetadataWorkspace metadataWorkspace, EntityContainer entityContainer) 10 | : base(metadataWorkspace, entityContainer) 11 | { 12 | } 13 | 14 | protected string GetTableName(EntitySet entitySet) 15 | { 16 | return (string)entitySet.MetadataProperties["Table"].Value; 17 | } 18 | 19 | protected override PrepareMappingRes PrepareMapping(string typeFullName, EdmType edmItem) 20 | { 21 | // find existing parent storageEntitySet 22 | // thp derived types does not have storageEntitySet 23 | EntitySet storageEntitySet; 24 | EdmType baseEdmType = edmItem; 25 | while (!EntityContainer.TryGetEntitySetByName(baseEdmType.Name, false, out storageEntitySet)) 26 | { 27 | if (baseEdmType.BaseType == null) 28 | { 29 | break; 30 | } 31 | baseEdmType = baseEdmType.BaseType; 32 | } 33 | 34 | if (storageEntitySet == null) 35 | { 36 | return null; 37 | } 38 | 39 | var isRoot = baseEdmType == edmItem; 40 | if (!isRoot) 41 | { 42 | var parent = _entityMaps.Values.FirstOrDefault(x => x.EdmType == baseEdmType); 43 | // parent table has not been mapped yet 44 | if (parent == null) 45 | { 46 | throw new ParentNotMappedYetException(); 47 | } 48 | } 49 | 50 | string tableName = GetTableName(storageEntitySet); 51 | 52 | return new PrepareMappingRes { TableName = tableName, StorageEntitySet = storageEntitySet, IsRoot = isRoot, BaseEdmType = baseEdmType }; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/Mappers/DbFirstMapper.cs: -------------------------------------------------------------------------------- 1 | using EntityFramework.MappingAPI.Exceptions; 2 | using System.Collections.Generic; 3 | using System.Data.Entity.Core.Mapping; 4 | using System.Data.Entity.Core.Metadata.Edm; 5 | using System.Linq; 6 | 7 | namespace EntityFramework.MappingAPI.Mappers 8 | { 9 | internal class DbFirstMapper : MapperBase 10 | { 11 | public DbFirstMapper(MetadataWorkspace metadataWorkspace, EntityContainer entityContainer) 12 | : base(metadataWorkspace, entityContainer) 13 | { 14 | } 15 | 16 | protected override PrepareMappingRes PrepareMapping(string typeFullName, EdmType edmItem) 17 | { 18 | string tableName = GetTableName(typeFullName); 19 | 20 | // find existing parent storageEntitySet 21 | // thp derived types does not have storageEntitySet 22 | EntitySet storageEntitySet; 23 | EdmType baseEdmType = edmItem; 24 | while (!EntityContainer.TryGetEntitySetByName(tableName, false, out storageEntitySet)) 25 | { 26 | if (baseEdmType.BaseType == null) 27 | { 28 | break; 29 | } 30 | baseEdmType = baseEdmType.BaseType; 31 | } 32 | 33 | if (storageEntitySet == null) 34 | { 35 | return null; 36 | } 37 | 38 | var isRoot = baseEdmType == edmItem; 39 | if (!isRoot) 40 | { 41 | var parent = _entityMaps.Values.FirstOrDefault(x => x.EdmType == baseEdmType); 42 | // parent table has not been mapped yet 43 | if (parent == null) 44 | { 45 | throw new ParentNotMappedYetException(); 46 | } 47 | } 48 | 49 | return new PrepareMappingRes { TableName = tableName, StorageEntitySet = storageEntitySet, IsRoot = isRoot, BaseEdmType = baseEdmType }; 50 | } 51 | 52 | /// 53 | /// 54 | /// 55 | /// 56 | /// 57 | protected string GetTableName(string typeFullName) 58 | { 59 | // Get the entity type from the model that maps to the CLR type 60 | var entityType = MetadataWorkspace.GetItems(DataSpace.OSpace).Single(e => e.FullName == typeFullName); 61 | 62 | 63 | // Get the entity set that uses this entity type 64 | var entitySet = MetadataWorkspace 65 | .GetItems(DataSpace.CSpace) 66 | .Single() 67 | .EntitySets 68 | .Single(s => s.ElementType.Name == entityType.Name); 69 | 70 | // Find the mapping between conceptual and storage model for this entity set 71 | var mapping = MetadataWorkspace.GetItems(DataSpace.CSSpace) 72 | .Single() 73 | .EntitySetMappings 74 | .Single(s => s.EntitySet == entitySet); 75 | 76 | // Find the storage entity sets (tables) that the entity is mapped 77 | var tables = mapping 78 | .EntityTypeMappings.Single() 79 | .Fragments; 80 | 81 | // Return the table name from the storage entity set 82 | return tables.Select(f => (string)f.StoreEntitySet.MetadataProperties["Table"].Value ?? f.StoreEntitySet.Name) 83 | .FirstOrDefault(); 84 | } 85 | 86 | protected override Dictionary GetTphData() 87 | { 88 | return base.GetTphData(); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/Mappers/TphData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Data.Entity.Core.Metadata.Edm; 3 | 4 | namespace EntityFramework.MappingAPI.Mappers 5 | { 6 | internal class TphData 7 | { 8 | public EdmMember[] Properties { get; set; } 9 | public NavigationProperty[] NavProperties { get; set; } 10 | 11 | public Dictionary Discriminators = new Dictionary(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/Mappings/DbMapping.cs: -------------------------------------------------------------------------------- 1 | using EntityFramework.MappingAPI.Exceptions; 2 | using EntityFramework.MappingAPI.Mappers; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Collections.ObjectModel; 6 | using System.Data.Entity; 7 | using System.Data.Entity.Core.Metadata.Edm; 8 | using System.Data.Entity.Infrastructure; 9 | using System.Linq; 10 | 11 | namespace EntityFramework.MappingAPI.Mappings 12 | { 13 | /// 14 | /// 15 | /// 16 | internal class DbMapping 17 | { 18 | private readonly Dictionary _tableMappings = new Dictionary(); 19 | private readonly string _contextTypeName; 20 | private readonly DbContext _context; 21 | 22 | /// 23 | /// 24 | /// 25 | /// 26 | public DbMapping(DbContext context) 27 | { 28 | _context = context; 29 | _contextTypeName = context.GetType().FullName; 30 | 31 | var objectContext = ((IObjectContextAdapter)context).ObjectContext; 32 | MetadataWorkspace metadataWorkspace = objectContext.MetadataWorkspace; 33 | 34 | MapperBase mapper; 35 | 36 | EntityContainer entityContainer; 37 | if (metadataWorkspace.TryGetEntityContainer("CodeFirstDatabase", true, DataSpace.SSpace, out entityContainer)) 38 | { 39 | mapper = new CodeFirstMapper(metadataWorkspace, entityContainer); 40 | } 41 | else 42 | { 43 | ReadOnlyCollection readOnlyCollection; 44 | 45 | readOnlyCollection = metadataWorkspace.GetItems(DataSpace.SSpace); 46 | entityContainer = readOnlyCollection[0]; 47 | mapper = new DbFirstMapper(metadataWorkspace, entityContainer); 48 | } 49 | 50 | var typeMappings = mapper.TypeMappings; 51 | 52 | int depth = 0; 53 | while (true) 54 | { 55 | if (depth > 100) 56 | { 57 | throw new Exception("Type mapping has reached unreasonable depth."); 58 | } 59 | 60 | if (typeMappings.Count == 0) 61 | { 62 | break; 63 | } 64 | 65 | var nextLevel = new Dictionary(); 66 | 67 | foreach (var kvp in typeMappings) 68 | { 69 | EntityMap entityMap; 70 | try 71 | { 72 | entityMap = mapper.MapEntity(kvp.Key, kvp.Value); 73 | } 74 | catch (ParentNotMappedYetException) 75 | { 76 | nextLevel.Add(kvp.Key, kvp.Value); 77 | continue; 78 | } 79 | 80 | if (entityMap == null) 81 | { 82 | continue; 83 | } 84 | 85 | _tableMappings.Add(kvp.Key, entityMap); 86 | } 87 | 88 | typeMappings = nextLevel; 89 | depth++; 90 | } 91 | 92 | mapper.BindForeignKeys(); 93 | } 94 | 95 | /// 96 | /// Tables in database 97 | /// 98 | public IEntityMap[] Tables { get { return _tableMappings.Values.ToArray(); } } 99 | 100 | /// 101 | /// Get table mapping by entity type 102 | /// 103 | /// 104 | /// 105 | public IEntityMap this[Type type] 106 | { 107 | get { return this[type.FullName]; } 108 | } 109 | 110 | /// 111 | /// Get table mapping by entity type full name 112 | /// 113 | /// 114 | /// 115 | public IEntityMap this[string typeFullName] 116 | { 117 | get 118 | { 119 | if (!_tableMappings.ContainsKey(typeFullName)) 120 | throw new Exception("Type '" + typeFullName + "' is not found in context '" + _contextTypeName + "'"); 121 | 122 | return _tableMappings[typeFullName]; 123 | } 124 | } 125 | 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/Mappings/EntityMap`1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace EntityFramework.MappingAPI.Mappings 5 | { 6 | internal class EntityMap : EntityMap, IEntityMap 7 | { 8 | public IPropertyMap Prop(Expression> predicate) 9 | { 10 | var predicateString = predicate.ToString(); 11 | var i = predicateString.IndexOf('.'); 12 | var propName = predicateString.Substring(i + 1); 13 | return base[propName]; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("EntityFramework.MappingAPI")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("EntityFramework.MappingAPI")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9aeb6eb0-f898-43cf-b894-bd8e52428e7c")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/EntityFramework.MappingAPI/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /tools/7-zip/7-zip.chm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/7-zip/7-zip.chm -------------------------------------------------------------------------------- /tools/7-zip/7za.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/7-zip/7za.exe -------------------------------------------------------------------------------- /tools/7-zip/license.txt: -------------------------------------------------------------------------------- 1 | 7-Zip Command line version 2 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | License for use and distribution 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | 7-Zip Copyright (C) 1999-2009 Igor Pavlov. 7 | 8 | 7za.exe is distributed under the GNU LGPL license 9 | 10 | Notes: 11 | You can use 7-Zip on any computer, including a computer in a commercial 12 | organization. You don't need to register or pay for 7-Zip. 13 | 14 | 15 | GNU LGPL information 16 | -------------------- 17 | 18 | This library is free software; you can redistribute it and/or 19 | modify it under the terms of the GNU Lesser General Public 20 | License as published by the Free Software Foundation; either 21 | version 2.1 of the License, or (at your option) any later version. 22 | 23 | This library is distributed in the hope that it will be useful, 24 | but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 26 | Lesser General Public License for more details. 27 | 28 | You should have received a copy of the GNU Lesser General Public 29 | License along with this library; if not, write to the Free Software 30 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 31 | -------------------------------------------------------------------------------- /tools/7-zip/readme.txt: -------------------------------------------------------------------------------- 1 | 7-Zip Command line version 4.65 2 | ------------------------------- 3 | 4 | 7-Zip is a file archiver with high compression ratio. 5 | 7za.exe is a standalone command line version of 7-Zip. 6 | 7 | 7-Zip Copyright (C) 1999-2009 Igor Pavlov. 8 | 9 | Features of 7za.exe: 10 | - High compression ratio in new 7z format 11 | - Supported formats: 12 | - Packing / unpacking: 7z, ZIP, GZIP, BZIP2 and TAR 13 | - Unpacking only: Z 14 | - Highest compression ratio for ZIP and GZIP formats. 15 | - Fast compression and decompression 16 | - Strong AES-256 encryption in 7z and ZIP formats. 17 | 18 | 7za.exe is a free software distributed under the GNU LGPL. 19 | Read license.txt for more information. 20 | 21 | Source code of 7za.exe and 7-Zip can be found at 22 | http://www.7-zip.org/ 23 | 24 | 7za.exe can work in Windows 95/98/ME/NT/2000/XP/2003/Vista. 25 | 26 | There is also port of 7za.exe for POSIX systems like Unix (Linux, Solaris, OpenBSD, 27 | FreeBSD, Cygwin, AIX, ...), MacOS X and BeOS: 28 | 29 | http://p7zip.sourceforge.net/ 30 | 31 | 32 | This distributive packet contains the following files: 33 | 34 | 7za.exe - 7-Zip standalone command line version. 35 | readme.txt - This file. 36 | copying.txt - GNU LGPL license. 37 | license.txt - License information. 38 | 7-zip.chm - User's Manual in HTML Help format. 39 | 40 | 41 | --- 42 | End of document 43 | -------------------------------------------------------------------------------- /tools/ILMerge/ILMerge.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/ILMerge/ILMerge.exe -------------------------------------------------------------------------------- /tools/ILMerge/System.Compiler.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/ILMerge/System.Compiler.dll -------------------------------------------------------------------------------- /tools/NUnit/framework/nunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/framework/nunit.framework.dll -------------------------------------------------------------------------------- /tools/NUnit/framework/nunit.mocks.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/framework/nunit.mocks.dll -------------------------------------------------------------------------------- /tools/NUnit/framework/pnunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/framework/pnunit.framework.dll -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Ellipsis.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Ellipsis.gif -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Circles/Failure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Circles/Failure.jpg -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Circles/Ignored.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Circles/Ignored.jpg -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Circles/Inconclusive.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Circles/Inconclusive.jpg -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Circles/Skipped.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Circles/Skipped.jpg -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Circles/Success.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Circles/Success.jpg -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Classic/Failure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Classic/Failure.jpg -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Classic/Ignored.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Classic/Ignored.jpg -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Classic/Inconclusive.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Classic/Inconclusive.jpg -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Classic/Skipped.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Classic/Skipped.jpg -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Classic/Success.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Classic/Success.jpg -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Default/Failure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Default/Failure.png -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Default/Ignored.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Default/Ignored.png -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Default/Inconclusive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Default/Inconclusive.png -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Default/Skipped.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Default/Skipped.png -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Default/Success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Default/Success.png -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Visual Studio/Failure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Visual Studio/Failure.png -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Visual Studio/Ignored.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Visual Studio/Ignored.png -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Visual Studio/Inconclusive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Visual Studio/Inconclusive.png -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Visual Studio/SeriousWarning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Visual Studio/SeriousWarning.png -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Visual Studio/Skipped.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Visual Studio/Skipped.png -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/Tree/Visual Studio/Success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/Tree/Visual Studio/Success.png -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/pinned.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/pinned.gif -------------------------------------------------------------------------------- /tools/NUnit/lib/Images/unpinned.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Images/unpinned.gif -------------------------------------------------------------------------------- /tools/NUnit/lib/NSubstitute.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/NSubstitute.dll -------------------------------------------------------------------------------- /tools/NUnit/lib/Rhino.Mocks.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/Rhino.Mocks.dll -------------------------------------------------------------------------------- /tools/NUnit/lib/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/log4net.dll -------------------------------------------------------------------------------- /tools/NUnit/lib/nunit-console-runner.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/nunit-console-runner.dll -------------------------------------------------------------------------------- /tools/NUnit/lib/nunit-gui-runner.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/nunit-gui-runner.dll -------------------------------------------------------------------------------- /tools/NUnit/lib/nunit.core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/nunit.core.dll -------------------------------------------------------------------------------- /tools/NUnit/lib/nunit.core.interfaces.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/nunit.core.interfaces.dll -------------------------------------------------------------------------------- /tools/NUnit/lib/nunit.uiexception.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/nunit.uiexception.dll -------------------------------------------------------------------------------- /tools/NUnit/lib/nunit.uikit.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/nunit.uikit.dll -------------------------------------------------------------------------------- /tools/NUnit/lib/nunit.util.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/lib/nunit.util.dll -------------------------------------------------------------------------------- /tools/NUnit/nunit-agent-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/nunit-agent-x86.exe -------------------------------------------------------------------------------- /tools/NUnit/nunit-agent-x86.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /tools/NUnit/nunit-agent.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/nunit-agent.exe -------------------------------------------------------------------------------- /tools/NUnit/nunit-agent.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /tools/NUnit/nunit-console-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/nunit-console-x86.exe -------------------------------------------------------------------------------- /tools/NUnit/nunit-console-x86.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /tools/NUnit/nunit-console.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/nunit-console.exe -------------------------------------------------------------------------------- /tools/NUnit/nunit-console.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /tools/NUnit/nunit-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/nunit-x86.exe -------------------------------------------------------------------------------- /tools/NUnit/nunit-x86.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /tools/NUnit/nunit.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NUnit/nunit.exe -------------------------------------------------------------------------------- /tools/NUnit/nunit.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /tools/NuGet/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghost1face/EntityFramework.BulkInsert/625e2ed7ba6cb8e396a4d54ba5d26426a8e8dbda/tools/NuGet/NuGet.exe -------------------------------------------------------------------------------- /tools/PSake/private/CleanupEnvironment.ps1: -------------------------------------------------------------------------------- 1 | function CleanupEnvironment { 2 | if ($psake.context.Count -gt 0) { 3 | $currentContext = $psake.context.Peek() 4 | $env:path = $currentContext.originalEnvPath 5 | Set-Location $currentContext.originalDirectory 6 | $global:ErrorActionPreference = $currentContext.originalErrorActionPreference 7 | [void] $psake.context.Pop() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tools/PSake/private/CreateConfigurationForNewContext.ps1: -------------------------------------------------------------------------------- 1 | function CreateConfigurationForNewContext { 2 | param( 3 | [string] $buildFile, 4 | [string] $framework 5 | ) 6 | 7 | $previousConfig = GetCurrentConfigurationOrDefault 8 | 9 | $config = new-object psobject -property @{ 10 | buildFileName = $previousConfig.buildFileName; 11 | framework = $previousConfig.framework; 12 | taskNameFormat = $previousConfig.taskNameFormat; 13 | verboseError = $previousConfig.verboseError; 14 | coloredOutput = $previousConfig.coloredOutput; 15 | modules = $previousConfig.modules; 16 | moduleScope = $previousConfig.moduleScope; 17 | } 18 | 19 | if ($framework) { 20 | $config.framework = $framework; 21 | } 22 | 23 | if ($buildFile) { 24 | $config.buildFileName = $buildFile; 25 | } 26 | 27 | return $config 28 | } 29 | -------------------------------------------------------------------------------- /tools/PSake/private/ExecuteInBuildFileScope.ps1: -------------------------------------------------------------------------------- 1 | function ExecuteInBuildFileScope { 2 | param([string]$buildFile, $module, [scriptblock]$sb) 3 | 4 | # Execute the build file to set up the tasks and defaults 5 | Assert (test-path $buildFile -pathType Leaf) ($msgs.error_build_file_not_found -f $buildFile) 6 | 7 | $psake.build_script_file = get-item $buildFile 8 | $psake.build_script_dir = $psake.build_script_file.DirectoryName 9 | $psake.build_success = $false 10 | 11 | $psake.context.push(@{ 12 | "taskSetupScriptBlock" = {}; 13 | "taskTearDownScriptBlock" = {}; 14 | "executedTasks" = new-object System.Collections.Stack; 15 | "callStack" = new-object System.Collections.Stack; 16 | "originalEnvPath" = $env:path; 17 | "originalDirectory" = get-location; 18 | "originalErrorActionPreference" = $global:ErrorActionPreference; 19 | "tasks" = @{}; 20 | "aliases" = @{}; 21 | "properties" = @(); 22 | "includes" = new-object System.Collections.Queue; 23 | "config" = CreateConfigurationForNewContext $buildFile $framework 24 | }) 25 | 26 | LoadConfiguration $psake.build_script_dir 27 | 28 | set-location $psake.build_script_dir 29 | 30 | LoadModules 31 | 32 | $frameworkOldValue = $framework 33 | . $psake.build_script_file.FullName 34 | 35 | $currentContext = $psake.context.Peek() 36 | 37 | if ($framework -ne $frameworkOldValue) { 38 | writecoloredoutput $msgs.warning_deprecated_framework_variable -foregroundcolor Yellow 39 | $currentContext.config.framework = $framework 40 | } 41 | 42 | ConfigureBuildEnvironment 43 | 44 | while ($currentContext.includes.Count -gt 0) { 45 | $includeFilename = $currentContext.includes.Dequeue() 46 | . $includeFilename 47 | } 48 | 49 | & $sb $currentContext $module 50 | } 51 | -------------------------------------------------------------------------------- /tools/PSake/private/Get-DefaultBuildFile.ps1: -------------------------------------------------------------------------------- 1 | # Attempt to find the default build file given the config_default of 2 | # buildFileName and legacyBuildFileName. If neither exist optionally 3 | # return the buildFileName or $null 4 | function Get-DefaultBuildFile { 5 | param( 6 | [boolean] $UseDefaultIfNoneExist = $true 7 | ) 8 | 9 | if (test-path $psake.config_default.buildFileName -pathType Leaf) { 10 | Write-Output $psake.config_default.buildFileName 11 | } elseif (test-path $psake.config_default.legacyBuildFileName -pathType Leaf) { 12 | Write-Warning "The default configuration file of default.ps1 is deprecated. Please use psakefile.ps1" 13 | Write-Output $psake.config_default.legacyBuildFileName 14 | } elseif ($UseDefaultIfNoneExist) { 15 | Write-Output $psake.config_default.buildFileName 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tools/PSake/private/GetCurrentConfigurationOrDefault.ps1: -------------------------------------------------------------------------------- 1 | function GetCurrentConfigurationOrDefault() { 2 | if ($psake.context.count -gt 0) { 3 | return $psake.context.peek().config 4 | } else { 5 | return $psake.config_default 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tools/PSake/private/GetTasksFromContext.ps1: -------------------------------------------------------------------------------- 1 | function GetTasksFromContext($currentContext) { 2 | 3 | $docs = $currentContext.tasks.Keys | foreach-object { 4 | 5 | $task = $currentContext.tasks.$_ 6 | new-object PSObject -property @{ 7 | Name = $task.Name; 8 | Alias = $task.Alias; 9 | Description = $task.Description; 10 | DependsOn = $task.DependsOn; 11 | } 12 | } 13 | 14 | return $docs 15 | } 16 | -------------------------------------------------------------------------------- /tools/PSake/private/LoadConfiguration.ps1: -------------------------------------------------------------------------------- 1 | function LoadConfiguration { 2 | param( 3 | [string] $configdir = $PSScriptRoot 4 | ) 5 | 6 | $psakeConfigFilePath = (join-path $configdir "psake-config.ps1") 7 | 8 | if (test-path $psakeConfigFilePath -pathType Leaf) { 9 | try { 10 | $config = GetCurrentConfigurationOrDefault 11 | . $psakeConfigFilePath 12 | } catch { 13 | throw "Error Loading Configuration from psake-config.ps1: " + $_ 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tools/PSake/private/LoadModules.ps1: -------------------------------------------------------------------------------- 1 | function LoadModules { 2 | $currentConfig = $psake.context.peek().config 3 | if ($currentConfig.modules) { 4 | 5 | $scope = $currentConfig.moduleScope 6 | 7 | $global = [string]::Equals($scope, "global", [StringComparison]::CurrentCultureIgnoreCase) 8 | 9 | $currentConfig.modules | foreach { 10 | resolve-path $_ | foreach { 11 | "Loading module: $_" 12 | $module = import-module $_ -passthru -DisableNameChecking -global:$global 13 | if (!$module) { 14 | throw ($msgs.error_loading_module -f $_.Name) 15 | } 16 | } 17 | } 18 | "" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tools/PSake/private/ResolveError.ps1: -------------------------------------------------------------------------------- 1 | # borrowed from Jeffrey Snover http://blogs.msdn.com/powershell/archive/2006/12/07/resolve-error.aspx 2 | # modified to better handle SQL errors 3 | function ResolveError 4 | { 5 | [CmdletBinding()] 6 | param( 7 | [Parameter(ValueFromPipeline=$true)] 8 | $ErrorRecord=$Error[0], 9 | [Switch] 10 | $Short 11 | ) 12 | 13 | process { 14 | if ($_ -eq $null) { $_ = $ErrorRecord } 15 | $ex = $_.Exception 16 | 17 | if (-not $Short) { 18 | $error_message = "`nErrorRecord:{0}ErrorRecord.InvocationInfo:{1}Exception:`n{2}" 19 | $formatted_errorRecord = $_ | format-list * -force | out-string 20 | $formatted_invocationInfo = $_.InvocationInfo | format-list * -force | out-string 21 | $formatted_exception = '' 22 | 23 | $i = 0 24 | while ($ex -ne $null) { 25 | $i++ 26 | $formatted_exception += ("$i" * 70) + "`n" + 27 | ($ex | format-list * -force | out-string) + "`n" 28 | $ex = $ex | SelectObjectWithDefault -Name 'InnerException' -Value $null 29 | } 30 | 31 | return $error_message -f $formatted_errorRecord, $formatted_invocationInfo, $formatted_exception 32 | } 33 | 34 | $lastException = @() 35 | while ($ex -ne $null) { 36 | $lastMessage = $ex | SelectObjectWithDefault -Name 'Message' -Value '' 37 | $lastException += ($lastMessage -replace "`n", '') 38 | if ($ex -is [Data.SqlClient.SqlException]) { 39 | $lastException += "(Line [$($ex.LineNumber)] " + 40 | "Procedure [$($ex.Procedure)] Class [$($ex.Class)] " + 41 | " Number [$($ex.Number)] State [$($ex.State)] )" 42 | } 43 | $ex = $ex | SelectObjectWithDefault -Name 'InnerException' -Value $null 44 | } 45 | $shortException = $lastException -join ' --> ' 46 | 47 | $header = $null 48 | $current = $_ 49 | $header = (($_.InvocationInfo | 50 | SelectObjectWithDefault -Name 'PositionMessage' -Value '') -replace "`n", ' '), 51 | ($_ | SelectObjectWithDefault -Name 'Message' -Value ''), 52 | ($_ | SelectObjectWithDefault -Name 'Exception' -Value '') | 53 | ? { -not [String]::IsNullOrEmpty($_) } | 54 | Select -First 1 55 | 56 | $delimiter = '' 57 | if ((-not [String]::IsNullOrEmpty($header)) -and 58 | (-not [String]::IsNullOrEmpty($shortException))) 59 | { $delimiter = ' [<<==>>] ' } 60 | 61 | return "$($header)$($delimiter)Exception: $($shortException)" 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tools/PSake/private/SelectObjectWithDefault.ps1: -------------------------------------------------------------------------------- 1 | function SelectObjectWithDefault 2 | { 3 | [CmdletBinding()] 4 | param( 5 | [Parameter(ValueFromPipeline=$true)] 6 | [PSObject] 7 | $InputObject, 8 | [string] 9 | $Name, 10 | $Value 11 | ) 12 | 13 | process { 14 | if ($_ -eq $null) { $Value } 15 | elseif ($_ | Get-Member -Name $Name) { 16 | $_.$Name 17 | } 18 | elseif (($_ -is [Hashtable]) -and ($_.Keys -contains $Name)) { 19 | $_.$Name 20 | } 21 | else { $Value } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tools/PSake/private/WriteColoredOutput.ps1: -------------------------------------------------------------------------------- 1 | function WriteColoredOutput { 2 | param( 3 | [string] $message, 4 | [System.ConsoleColor] $foregroundcolor 5 | ) 6 | 7 | $currentConfig = GetCurrentConfigurationOrDefault 8 | if ($currentConfig.coloredOutput -eq $true) { 9 | if (($Host.UI -ne $null) -and ($Host.UI.RawUI -ne $null) -and ($Host.UI.RawUI.ForegroundColor -ne $null)) { 10 | $previousColor = $Host.UI.RawUI.ForegroundColor 11 | $Host.UI.RawUI.ForegroundColor = $foregroundcolor 12 | } 13 | } 14 | 15 | $message 16 | 17 | if ($previousColor -ne $null) { 18 | $Host.UI.RawUI.ForegroundColor = $previousColor 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tools/PSake/private/WriteDocumentation.ps1: -------------------------------------------------------------------------------- 1 | function WriteDocumentation($showDetailed) { 2 | 3 | $currentContext = $psake.context.Peek() 4 | 5 | if ($currentContext.tasks.default) { 6 | $defaultTaskDependencies = $currentContext.tasks.default.DependsOn 7 | } else { 8 | $defaultTaskDependencies = @() 9 | } 10 | 11 | $docs = GetTasksFromContext $currentContext | 12 | Where {$_.Name -ne 'default'} | 13 | ForEach { 14 | $isDefault = $null 15 | if ($defaultTaskDependencies -contains $_.Name) { 16 | $isDefault = $true 17 | } 18 | return Add-Member -InputObject $_ 'Default' $isDefault -PassThru 19 | } 20 | 21 | if ($showDetailed) { 22 | $docs | Sort-Object 'Name' | format-list -property Name,Alias,Description,@{Label="Depends On";Expression={$_.DependsOn -join ', '}},Default 23 | } else { 24 | $docs | Sort-Object 'Name' | format-table -autoSize -wrap -property Name,Alias,@{Label="Depends On";Expression={$_.DependsOn -join ', '}},Default,Description 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tools/PSake/private/WriteTaskTimeSummary.ps1: -------------------------------------------------------------------------------- 1 | function WriteTaskTimeSummary($invokePsakeDuration) { 2 | if ($psake.context.count -gt 0) { 3 | $currentContext = $psake.context.Peek() 4 | if ($currentContext.config.taskNameFormat -is [ScriptBlock]) { 5 | & $currentContext.config.taskNameFormat "Build Time Report" 6 | } elseif ($currentContext.config.taskNameFormat -ne "Executing {0}") { 7 | $currentContext.config.taskNameFormat -f "Build Time Report" 8 | } 9 | else { 10 | "-" * 70 11 | "Build Time Report" 12 | "-" * 70 13 | } 14 | $list = @() 15 | while ($currentContext.executedTasks.Count -gt 0) { 16 | $taskKey = $currentContext.executedTasks.Pop() 17 | $task = $currentContext.tasks.$taskKey 18 | if ($taskKey -eq "default") { 19 | continue 20 | } 21 | $list += new-object PSObject -property @{ 22 | Name = $task.Name; 23 | Duration = $task.Duration.ToString("hh\:mm\:ss\.fff") 24 | } 25 | } 26 | [Array]::Reverse($list) 27 | $list += new-object PSObject -property @{ 28 | Name = "Total:"; 29 | Duration = $invokePsakeDuration.ToString("hh\:mm\:ss\.fff") 30 | } 31 | # using "out-string | where-object" to filter out the blank line that format-table prepends 32 | $list | format-table -autoSize -property Name,Duration | out-string -stream | where-object { $_ } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tools/PSake/psake-config.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | ------------------------------------------------------------------- 3 | Defaults 4 | ------------------------------------------------------------------- 5 | $config.buildFileName="psakefile.ps1" 6 | $config.legacyBuildFileName="default.ps1" 7 | $config.framework = "4.0" 8 | $config.taskNameFormat="Executing {0}" 9 | $config.verboseError=$false 10 | $config.coloredOutput = $true 11 | $config.modules=$null 12 | 13 | ------------------------------------------------------------------- 14 | Load modules from .\modules folder and from file my_module.psm1 15 | ------------------------------------------------------------------- 16 | $config.modules=(".\modules\*.psm1",".\my_module.psm1") 17 | 18 | ------------------------------------------------------------------- 19 | Use scriptblock for taskNameFormat 20 | ------------------------------------------------------------------- 21 | $config.taskNameFormat= { param($taskName) "Executing $taskName at $(get-date)" } 22 | #> 23 | -------------------------------------------------------------------------------- /tools/PSake/psake.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem Helper script for those who want to run psake from cmd.exe 3 | rem Example run from cmd.exe: 4 | rem psake "psakefile.ps1" "BuildHelloWord" "4.0" 5 | 6 | if '%1'=='/?' goto help 7 | if '%1'=='-help' goto help 8 | if '%1'=='-h' goto help 9 | 10 | powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0\psake.ps1' %*; if ($psake.build_success -eq $false) { exit 1 } else { exit 0 }" 11 | exit /B %errorlevel% 12 | 13 | :help 14 | powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0\psake.ps1' -help" 15 | -------------------------------------------------------------------------------- /tools/PSake/psake.ps1: -------------------------------------------------------------------------------- 1 | # Helper script for those who want to run psake without importing the module. 2 | # Example run from PowerShell: 3 | # .\psake.ps1 "psakefile.ps1" "BuildHelloWord" "4.0" 4 | 5 | # Must match parameter definitions for psake.psm1/invoke-psake 6 | # otherwise named parameter binding fails 7 | [cmdletbinding()] 8 | param( 9 | [Parameter(Position = 0, Mandatory = $false)] 10 | [string]$buildFile, 11 | 12 | [Parameter(Position = 1, Mandatory = $false)] 13 | [string[]]$taskList = @(), 14 | 15 | [Parameter(Position = 2, Mandatory = $false)] 16 | [string]$framework, 17 | 18 | [Parameter(Position = 3, Mandatory = $false)] 19 | [switch]$docs = $false, 20 | 21 | [Parameter(Position = 4, Mandatory = $false)] 22 | [System.Collections.Hashtable]$parameters = @{}, 23 | 24 | [Parameter(Position = 5, Mandatory = $false)] 25 | [System.Collections.Hashtable]$properties = @{}, 26 | 27 | [Parameter(Position = 6, Mandatory = $false)] 28 | [alias("init")] 29 | [scriptblock]$initialization = {}, 30 | 31 | [Parameter(Position = 7, Mandatory = $false)] 32 | [switch]$nologo = $false, 33 | 34 | [Parameter(Position = 8, Mandatory = $false)] 35 | [switch]$help = $false, 36 | 37 | [Parameter(Position = 9, Mandatory = $false)] 38 | [string]$scriptPath, 39 | 40 | [Parameter(Position = 10, Mandatory = $false)] 41 | [switch]$detailedDocs = $false, 42 | 43 | [Parameter(Position = 11, Mandatory = $false)] 44 | [switch]$notr = $false 45 | ) 46 | 47 | # setting $scriptPath here, not as default argument, to support calling as "powershell -File psake.ps1" 48 | if (-not $scriptPath) { 49 | $scriptPath = $(Split-Path -Path $MyInvocation.MyCommand.path -Parent) 50 | } 51 | 52 | # '[p]sake' is the same as 'psake' but $Error is not polluted 53 | Remove-Module -Name [p]sake -Verbose:$false 54 | Import-Module -Name (Join-Path -Path $scriptPath -ChildPath 'psake.psd1') -Verbose:$false 55 | if ($help) { 56 | Get-Help -Name Invoke-psake -Full 57 | return 58 | } 59 | 60 | if ($buildFile -and (-not (Test-Path -Path $buildFile))) { 61 | $absoluteBuildFile = (Join-Path -Path $scriptPath -ChildPath $buildFile) 62 | if (Test-path -Path $absoluteBuildFile) { 63 | $buildFile = $absoluteBuildFile 64 | } 65 | } 66 | 67 | Invoke-psake $buildFile $taskList $framework $docs $parameters $properties $initialization $nologo $detailedDocs $notr 68 | -------------------------------------------------------------------------------- /tools/PSake/psake.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | RootModule = 'psake.psm1' 3 | ModuleVersion = '4.7.0' 4 | GUID = 'cfb53216-072f-4a46-8975-ff7e6bda05a5' 5 | Author = 'James Kovacs' 6 | Copyright = 'Copyright (c) 2010-17 James Kovacs, Damian Hickey and Contributors' 7 | PowerShellVersion = '3.0' 8 | Description = 'psake is a build automation tool written in PowerShell.' 9 | FunctionsToExport = @('Invoke-psake', 10 | 'Invoke-Task', 11 | 'Get-PSakeScriptTasks', 12 | 'Task', 13 | 'Properties', 14 | 'Include', 15 | 'FormatTaskName', 16 | 'TaskSetup', 17 | 'TaskTearDown', 18 | 'Framework', 19 | 'Assert', 20 | 'Exec') 21 | VariablesToExport = 'psake' 22 | PrivateData = @{ 23 | PSData = @{ 24 | LicenseUri = 'https://github.com/psake/psake/blob/master/license.txt' 25 | ProjectUri = 'https://github.com/psake/psake' 26 | Tags = @('Build', 'Task') 27 | IconUri = 'https://raw.githubusercontent.com/psake/graphics/master/png/psake-single-icon-teal-bg-256x256.png' 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tools/PSake/public/Assert.ps1: -------------------------------------------------------------------------------- 1 | function Assert { 2 | <# 3 | .SYNOPSIS 4 | Helper function for "Design by Contract" assertion checking. 5 | 6 | .DESCRIPTION 7 | This is a helper function that makes the code less noisy by eliminating many of the "if" statements that are normally required to verify assumptions in the code. 8 | 9 | .PARAMETER conditionToCheck 10 | The boolean condition to evaluate 11 | 12 | .PARAMETER failureMessage 13 | The error message used for the exception if the conditionToCheck parameter is false 14 | 15 | .EXAMPLE 16 | C:\PS>Assert $false "This always throws an exception" 17 | 18 | Example of an assertion that will always fail. 19 | 20 | .EXAMPLE 21 | C:\PS>Assert ( ($i % 2) -eq 0 ) "$i is not an even number" 22 | 23 | This exmaple may throw an exception if $i is not an even number 24 | 25 | Note: 26 | It might be necessary to wrap the condition with paranthesis to force PS to evaluate the condition 27 | so that a boolean value is calculated and passed into the 'conditionToCheck' parameter. 28 | 29 | Example: 30 | Assert 1 -eq 2 "1 doesn't equal 2" 31 | 32 | PS will pass 1 into the condtionToCheck variable and PS will look for a parameter called "eq" and 33 | throw an exception with the following message "A parameter cannot be found that matches parameter name 'eq'" 34 | 35 | The solution is to wrap the condition in () so that PS will evaluate it first. 36 | 37 | Assert (1 -eq 2) "1 doesn't equal 2" 38 | .LINK 39 | Exec 40 | .LINK 41 | FormatTaskName 42 | .LINK 43 | Framework 44 | .LINK 45 | Get-PSakeScriptTasks 46 | .LINK 47 | Include 48 | .LINK 49 | Invoke-psake 50 | .LINK 51 | Properties 52 | .LINK 53 | Task 54 | .LINK 55 | TaskSetup 56 | .LINK 57 | TaskTearDown 58 | #> 59 | [CmdletBinding()] 60 | param( 61 | [Parameter(Mandatory = $true)] 62 | $conditionToCheck, 63 | 64 | [Parameter(Mandatory = $true)] 65 | [string]$failureMessage 66 | ) 67 | 68 | if (-not $conditionToCheck) { 69 | throw ('Assert: {0}' -f $failureMessage) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tools/PSake/public/Exec.ps1: -------------------------------------------------------------------------------- 1 | function Exec { 2 | <# 3 | .SYNOPSIS 4 | Helper function for executing command-line programs. 5 | 6 | .DESCRIPTION 7 | This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode to see if an error occcured. 8 | If an error is detected then an exception is thrown. 9 | This function allows you to run command-line programs without having to explicitly check fthe $lastexitcode variable. 10 | 11 | .PARAMETER cmd 12 | The scriptblock to execute. This scriptblock will typically contain the command-line invocation. 13 | 14 | .PARAMETER errorMessage 15 | The error message to display if the external command returned a non-zero exit code. 16 | 17 | .PARAMETER maxRetries 18 | The maximum number of times to retry the command before failing. 19 | 20 | .PARAMETER retryTriggerErrorPattern 21 | If the external command raises an exception, match the exception against this regex to determine if the command can be retried. 22 | If a match is found, the command will be retried provided [maxRetries] has not been reached. 23 | 24 | .PARAMETER workingDirectory 25 | The working directory to set before running the external command. 26 | 27 | .EXAMPLE 28 | exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed" 29 | 30 | This example calls the svn command-line client. 31 | .LINK 32 | Assert 33 | .LINK 34 | FormatTaskName 35 | .LINK 36 | Framework 37 | .LINK 38 | Get-PSakeScriptTasks 39 | .LINK 40 | Include 41 | .LINK 42 | Invoke-psake 43 | .LINK 44 | Properties 45 | .LINK 46 | Task 47 | .LINK 48 | TaskSetup 49 | .LINK 50 | TaskTearDown 51 | .LINK 52 | Properties 53 | #> 54 | [CmdletBinding()] 55 | param( 56 | [Parameter(Mandatory = $true)] 57 | [scriptblock]$cmd, 58 | 59 | [string]$errorMessage = ($msgs.error_bad_command -f $cmd), 60 | 61 | [int]$maxRetries = 0, 62 | 63 | [string]$retryTriggerErrorPattern = $null, 64 | 65 | [string]$workingDirectory = $null 66 | ) 67 | 68 | if ($workingDirectory) { 69 | Push-Location -Path $workingDirectory 70 | } 71 | 72 | $tryCount = 1 73 | 74 | do { 75 | try { 76 | $global:lastexitcode = 0 77 | & $cmd 78 | if ($lastexitcode -ne 0) { 79 | throw "Exec: $errorMessage" 80 | } 81 | break 82 | } 83 | catch [Exception] { 84 | if ($tryCount -gt $maxRetries) { 85 | throw $_ 86 | } 87 | 88 | if ($retryTriggerErrorPattern -ne $null) { 89 | $isMatch = [regex]::IsMatch($_.Exception.Message, $retryTriggerErrorPattern) 90 | 91 | if ($isMatch -eq $false) { 92 | throw $_ 93 | } 94 | } 95 | 96 | Write-Host "Try $tryCount failed, retrying again in 1 second..." 97 | 98 | $tryCount++ 99 | 100 | [System.Threading.Thread]::Sleep([System.TimeSpan]::FromSeconds(1)) 101 | } 102 | finally { 103 | if ($workingDirectory) { 104 | Pop-Location 105 | } 106 | } 107 | } 108 | while ($true) 109 | } 110 | -------------------------------------------------------------------------------- /tools/PSake/public/FormatTaskName.ps1: -------------------------------------------------------------------------------- 1 | function FormatTaskName { 2 | <# 3 | .SYNOPSIS 4 | This function allows you to change how psake renders the task name during a build. 5 | 6 | .DESCRIPTION 7 | This function takes either a string which represents a format string (formats using the -f format operator see "help about_operators") or it can accept a script block that has a single parameter that is the name of the task that will be executed. 8 | 9 | .PARAMETER format 10 | A format string or a scriptblock to execute 11 | 12 | .EXAMPLE 13 | A sample build script that uses a format string is shown below: 14 | 15 | Task default -depends TaskA, TaskB, TaskC 16 | 17 | FormatTaskName "-------- {0} --------" 18 | 19 | Task TaskA { 20 | "TaskA is executing" 21 | } 22 | 23 | Task TaskB { 24 | "TaskB is executing" 25 | } 26 | 27 | Task TaskC { 28 | "TaskC is executing" 29 | 30 | ----------- 31 | The script above produces the following output: 32 | 33 | -------- TaskA -------- 34 | TaskA is executing 35 | -------- TaskB -------- 36 | TaskB is executing 37 | -------- TaskC -------- 38 | TaskC is executing 39 | 40 | Build Succeeded! 41 | .EXAMPLE 42 | A sample build script that uses a ScriptBlock is shown below: 43 | 44 | Task default -depends TaskA, TaskB, TaskC 45 | 46 | FormatTaskName { 47 | param($taskName) 48 | write-host "Executing Task: $taskName" -foregroundcolor blue 49 | } 50 | 51 | Task TaskA { 52 | "TaskA is executing" 53 | } 54 | 55 | Task TaskB { 56 | "TaskB is executing" 57 | } 58 | 59 | Task TaskC { 60 | "TaskC is executing" 61 | } 62 | 63 | ----------- 64 | The above example uses the scriptblock parameter to the FormatTaskName function to render each task name in the color blue. 65 | 66 | Note: the $taskName parameter is arbitrary, it could be named anything. 67 | .LINK 68 | Assert 69 | .LINK 70 | Exec 71 | .LINK 72 | Framework 73 | .LINK 74 | Get-PSakeScriptTasks 75 | .LINK 76 | Include 77 | .LINK 78 | Invoke-psake 79 | .LINK 80 | Properties 81 | .LINK 82 | Task 83 | .LINK 84 | TaskSetup 85 | .LINK 86 | TaskTearDown 87 | #> 88 | [CmdletBinding()] 89 | param( 90 | [Parameter(Mandatory = $true)] 91 | $format 92 | ) 93 | 94 | $psake.context.Peek().config.taskNameFormat = $format 95 | } 96 | -------------------------------------------------------------------------------- /tools/PSake/public/Framework.ps1: -------------------------------------------------------------------------------- 1 | function Framework { 2 | <# 3 | .SYNOPSIS 4 | Sets the version of the .NET framework you want to use during build. 5 | 6 | .DESCRIPTION 7 | This function will accept a string containing version of the .NET framework to use during build. 8 | Possible values: '1.0', '1.1', '2.0', '2.0x86', '2.0x64', '3.0', '3.0x86', '3.0x64', '3.5', '3.5x86', '3.5x64', '4.0', '4.0x86', '4.0x64', '4.5', '4.5x86', '4.5x64', '4.5.1', '4.5.1x86', '4.5.1x64'. 9 | Default is '3.5*', where x86 or x64 will be detected based on the bitness of the PowerShell process. 10 | 11 | .PARAMETER framework 12 | Version of the .NET framework to use during build. 13 | 14 | .EXAMPLE 15 | Framework "4.0" 16 | 17 | Task default -depends Compile 18 | 19 | Task Compile -depends Clean { 20 | msbuild /version 21 | } 22 | 23 | ----------- 24 | The script above will output detailed version of msbuid v4 25 | .LINK 26 | Assert 27 | .LINK 28 | Exec 29 | .LINK 30 | FormatTaskName 31 | .LINK 32 | Get-PSakeScriptTasks 33 | .LINK 34 | Include 35 | .LINK 36 | Invoke-psake 37 | .LINK 38 | Properties 39 | .LINK 40 | Task 41 | .LINK 42 | TaskSetup 43 | .LINK 44 | TaskTearDown 45 | #> 46 | [CmdletBinding()] 47 | param( 48 | [Parameter(Mandatory = $true)] 49 | [string]$framework 50 | ) 51 | 52 | $psake.context.Peek().config.framework = $framework 53 | 54 | ConfigureBuildEnvironment 55 | } 56 | -------------------------------------------------------------------------------- /tools/PSake/public/Get-PSakeScriptTasks.ps1: -------------------------------------------------------------------------------- 1 | function Get-PSakeScriptTasks { 2 | <# 3 | .SYNOPSIS 4 | Returns meta data about all the tasks defined in the provided psake script. 5 | 6 | .DESCRIPTION 7 | Returns meta data about all the tasks defined in the provided psake script. 8 | 9 | .PARAMETER buildFile 10 | The path to the psake build script to read the tasks from. 11 | 12 | .EXAMPLE 13 | PS C:\>Get-PSakeScriptTasks -buildFile '.\build.ps1' 14 | 15 | DependsOn Alias Name Description 16 | --------- ----- ---- ----------- 17 | {} Compile 18 | {} Clean 19 | {Test} Default 20 | {Clean, Compile} Test 21 | 22 | Gets the psake tasks contained in the 'build.ps1' file. 23 | 24 | .LINK 25 | Invoke-psake 26 | #> 27 | [CmdletBinding()] 28 | param( 29 | [string]$buildFile 30 | ) 31 | 32 | if (-not $buildFile) { 33 | $buildFile = $psake.config_default.buildFileName 34 | } 35 | 36 | try { 37 | ExecuteInBuildFileScope $buildFile $MyInvocation.MyCommand.Module { 38 | param($currentContext, $module) 39 | return GetTasksFromContext $currentContext 40 | } 41 | } finally { 42 | CleanupEnvironment 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tools/PSake/public/Include.ps1: -------------------------------------------------------------------------------- 1 | function Include { 2 | <# 3 | .SYNOPSIS 4 | Include the functions or code of another powershell script file into the current build script's scope 5 | 6 | .DESCRIPTION 7 | A build script may declare an "includes" function which allows you to define a file containing powershell code to be included 8 | and added to the scope of the currently running build script. Code from such file will be executed after code from build script. 9 | 10 | .PARAMETER fileNamePathToInclude 11 | A string containing the path and name of the powershell file to include 12 | 13 | .EXAMPLE 14 | A sample build script is shown below: 15 | 16 | Include ".\build_utils.ps1" 17 | 18 | Task default -depends Test 19 | 20 | Task Test -depends Compile, Clean { 21 | } 22 | 23 | Task Compile -depends Clean { 24 | } 25 | 26 | Task Clean { 27 | } 28 | 29 | ----------- 30 | The script above includes all the functions and variables defined in the ".\build_utils.ps1" script into the current build script's scope 31 | 32 | Note: You can have more than 1 "Include" function defined in the build script. 33 | 34 | .LINK 35 | Assert 36 | .LINK 37 | Exec 38 | .LINK 39 | FormatTaskName 40 | .LINK 41 | Framework 42 | .LINK 43 | Get-PSakeScriptTasks 44 | .LINK 45 | Invoke-psake 46 | .LINK 47 | Properties 48 | .LINK 49 | Task 50 | .LINK 51 | TaskSetup 52 | .LINK 53 | TaskTearDown 54 | #> 55 | [CmdletBinding()] 56 | param( 57 | [Parameter(Mandatory = $true)] 58 | [string]$fileNamePathToInclude 59 | ) 60 | 61 | Assert (test-path $fileNamePathToInclude -pathType Leaf) ($msgs.error_invalid_include_path -f $fileNamePathToInclude) 62 | 63 | $psake.context.Peek().includes.Enqueue((Resolve-Path $fileNamePathToInclude)); 64 | } 65 | -------------------------------------------------------------------------------- /tools/PSake/public/Properties.ps1: -------------------------------------------------------------------------------- 1 | function Properties { 2 | <# 3 | .SYNOPSIS 4 | Define a scriptblock that contains assignments to variables that will be available to all tasks in the build script 5 | 6 | .DESCRIPTION 7 | A build script may declare a "Properies" function which allows you to define variables that will be available to all the "Task" functions in the build script. 8 | 9 | .PARAMETER properties 10 | The script block containing all the variable assignment statements 11 | 12 | .EXAMPLE 13 | A sample build script is shown below: 14 | 15 | Properties { 16 | $build_dir = "c:\build" 17 | $connection_string = "datasource=localhost;initial catalog=northwind;integrated security=sspi" 18 | } 19 | 20 | Task default -depends Test 21 | 22 | Task Test -depends Compile, Clean { 23 | } 24 | 25 | Task Compile -depends Clean { 26 | } 27 | 28 | Task Clean { 29 | } 30 | 31 | Note: You can have more than one "Properties" function defined in the build script. 32 | 33 | .LINK 34 | Assert 35 | .LINK 36 | Exec 37 | .LINK 38 | FormatTaskName 39 | .LINK 40 | Framework 41 | .LINK 42 | Get-PSakeScriptTasks 43 | .LINK 44 | Include 45 | .LINK 46 | Invoke-psake 47 | .LINK 48 | Task 49 | .LINK 50 | TaskSetup 51 | .LINK 52 | TaskTearDown 53 | #> 54 | [CmdletBinding()] 55 | param( 56 | [Parameter(Mandatory = $true)] 57 | [scriptblock]$properties 58 | ) 59 | 60 | $psake.context.Peek().properties += $properties 61 | } 62 | -------------------------------------------------------------------------------- /tools/PSake/public/TaskSetup.ps1: -------------------------------------------------------------------------------- 1 | function TaskSetup { 2 | <# 3 | .SYNOPSIS 4 | Adds a scriptblock that will be executed before each task 5 | 6 | .DESCRIPTION 7 | This function will accept a scriptblock that will be executed before each task in the build script. 8 | 9 | .PARAMETER setup 10 | A scriptblock to execute 11 | 12 | .EXAMPLE 13 | A sample build script is shown below: 14 | 15 | Task default -depends Test 16 | 17 | Task Test -depends Compile, Clean { 18 | } 19 | 20 | Task Compile -depends Clean { 21 | } 22 | 23 | Task Clean { 24 | } 25 | 26 | TaskSetup { 27 | "Running 'TaskSetup' for task $context.Peek().currentTaskName" 28 | } 29 | 30 | The script above produces the following output: 31 | 32 | Running 'TaskSetup' for task Clean 33 | Executing task, Clean... 34 | Running 'TaskSetup' for task Compile 35 | Executing task, Compile... 36 | Running 'TaskSetup' for task Test 37 | Executing task, Test... 38 | 39 | Build Succeeded 40 | 41 | .LINK 42 | Assert 43 | .LINK 44 | Exec 45 | .LINK 46 | FormatTaskName 47 | .LINK 48 | Framework 49 | .LINK 50 | Get-PSakeScriptTasks 51 | .LINK 52 | Include 53 | .LINK 54 | Invoke-psake 55 | .LINK 56 | Properties 57 | .LINK 58 | Task 59 | .LINK 60 | TaskTearDown 61 | #> 62 | [CmdletBinding()] 63 | param( 64 | [Parameter(Mandatory = $true)] 65 | [scriptblock]$setup 66 | ) 67 | 68 | $psake.context.Peek().taskSetupScriptBlock = $setup 69 | } 70 | -------------------------------------------------------------------------------- /tools/PSake/public/TaskTearDown.ps1: -------------------------------------------------------------------------------- 1 | 2 | function TaskTearDown { 3 | <# 4 | .SYNOPSIS 5 | Adds a scriptblock to the build that will be executed after each task 6 | 7 | .DESCRIPTION 8 | This function will accept a scriptblock that will be executed after each task in the build script. 9 | 10 | .PARAMETER teardown 11 | A scriptblock to execute 12 | 13 | .EXAMPLE 14 | A sample build script is shown below: 15 | 16 | Task default -depends Test 17 | 18 | Task Test -depends Compile, Clean { 19 | } 20 | 21 | Task Compile -depends Clean { 22 | } 23 | 24 | Task Clean { 25 | } 26 | 27 | TaskTearDown { 28 | "Running 'TaskTearDown' for task $context.Peek().currentTaskName" 29 | } 30 | 31 | The script above produces the following output: 32 | 33 | Executing task, Clean... 34 | Running 'TaskTearDown' for task Clean 35 | Executing task, Compile... 36 | Running 'TaskTearDown' for task Compile 37 | Executing task, Test... 38 | Running 'TaskTearDown' for task Test 39 | 40 | Build Succeeded 41 | 42 | .LINK 43 | Assert 44 | .LINK 45 | Exec 46 | .LINK 47 | FormatTaskName 48 | .LINK 49 | Framework 50 | .LINK 51 | Get-PSakeScriptTasks 52 | .LINK 53 | Include 54 | .LINK 55 | Invoke-psake 56 | .LINK 57 | Properties 58 | .LINK 59 | Task 60 | .LINK 61 | TaskSetup 62 | #> 63 | [CmdletBinding()] 64 | param( 65 | [Parameter(Mandatory = $true)] 66 | [scriptblock]$teardown 67 | ) 68 | 69 | $psake.context.Peek().taskTearDownScriptBlock = $teardown 70 | } 71 | --------------------------------------------------------------------------------