├── .gitignore ├── CosmosDB ├── Data │ └── NorthwindContext.cs ├── Models │ ├── Customer.cs │ ├── Employee.cs │ └── Order.cs ├── Northwind.CosmosDB.csproj └── Program.cs ├── LICENSE ├── MS SQL Server ├── Database │ ├── Loading Related Data.sql │ ├── Northwind.bak │ └── northwind.sql └── Northwind.MSSQL │ ├── Controllers │ ├── CustomersController.cs │ └── WeatherForecastController.cs │ ├── Data │ ├── DbContextExtensions.cs │ ├── NorthwindContext.cs │ └── NorthwindContextProcedures.cs │ ├── Models │ ├── AlphabeticalListOfProduct.cs │ ├── Category.cs │ ├── CategorySalesFor1997.cs │ ├── CurrentProductList.cs │ ├── CustOrderHistResult.cs │ ├── CustOrdersDetailResult.cs │ ├── CustOrdersOrdersResult.cs │ ├── Customer.cs │ ├── CustomerAndSuppliersByCity.cs │ ├── Employee.cs │ ├── EmployeeSalesbyCountryResult.cs │ ├── Invoice.cs │ ├── Order.cs │ ├── OrderDetail.cs │ ├── OrderDetailsExtended.cs │ ├── OrderSubtotal.cs │ ├── OrdersQry.cs │ ├── Product.cs │ ├── ProductSalesFor1997.cs │ ├── ProductsAboveAveragePrice.cs │ ├── ProductsByCategory.cs │ ├── QuarterlyOrder.cs │ ├── SalesByCategory.cs │ ├── SalesByCategoryResult.cs │ ├── SalesTotalsByAmount.cs │ ├── SalesbyYearResult.cs │ ├── Shipper.cs │ ├── SummaryOfSalesByQuarter.cs │ ├── SummaryOfSalesByYear.cs │ ├── Supplier.cs │ └── TenMostExpensiveProductsResult.cs │ ├── Northwind.MSSQL.csproj │ ├── Northwind.MSSQL.sln │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── WeatherForecast.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ └── efpt.config.json ├── MySQL ├── Database │ ├── Loading Related Data.sql │ └── northwind.sql ├── Northwind.MySQL │ ├── Controllers │ │ ├── ProductsController.cs │ │ └── WeatherForecastController.cs │ ├── Data │ │ └── NorthwindContext.cs │ ├── Models │ │ ├── AlphabeticalListOfProduct.cs │ │ ├── Category.cs │ │ ├── Customer.cs │ │ ├── Employee.cs │ │ ├── Order.cs │ │ ├── Orderdetail.cs │ │ ├── Product.cs │ │ ├── Shipper.cs │ │ └── Supplier.cs │ ├── Northwind.MySQL.csproj │ ├── Northwind.MySQL.sln │ ├── Procedures │ │ ├── CustOrderHistory.cs │ │ └── NorthwindContextProcedures.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── WeatherForecast.cs │ ├── appsettings.Development.json │ └── appsettings.json └── Steps.txt ├── README.md └── SQLite ├── Database ├── Load Related Data.sql └── northwind.sqlite ├── Northwind.SQLite ├── Controllers │ ├── ProductsController.cs │ └── WeatherForecastController.cs ├── Data │ └── NorthwindContext.cs ├── Models │ ├── Category.cs │ ├── Customer.cs │ ├── Employee.cs │ ├── EmployeeTerritory.cs │ ├── Order.cs │ ├── OrderDetail.cs │ ├── Product.cs │ ├── ProductDetail.cs │ ├── Region.cs │ ├── Shipper.cs │ ├── Supplier.cs │ └── Territory.cs ├── Northwind.SQLite.csproj ├── Northwind.SQLite.sln ├── Program.cs ├── Properties │ └── launchSettings.json ├── WeatherForecast.cs ├── appsettings.Development.json └── appsettings.json └── Steps.txt /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /CosmosDB/Data/NorthwindContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Northwind.Models; 3 | 4 | namespace Northwind.Data; 5 | 6 | public class NorthwindContext : DbContext 7 | { 8 | public DbSet? Employees { get; set; } 9 | public DbSet? Customers { get; set; } 10 | 11 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 12 | { 13 | optionsBuilder.UseCosmos( 14 | "accountEndpoint", 15 | "accountKey", 16 | "databaseName"); 17 | } 18 | 19 | protected override void OnModelCreating(ModelBuilder modelBuilder) 20 | { 21 | // configuring Employees 22 | modelBuilder.Entity() 23 | .ToContainer("Employees") // ToContainer 24 | .HasPartitionKey(e => e.Id); // Partition Key 25 | 26 | // configuring Customers 27 | modelBuilder.Entity() 28 | .ToContainer("Customers") // ToContainer 29 | .HasPartitionKey(c => c.Id); // Partition Key 30 | 31 | modelBuilder.Entity().OwnsMany(p => p.Orders); 32 | } 33 | } -------------------------------------------------------------------------------- /CosmosDB/Models/Customer.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Models; 2 | 3 | public class Customer 4 | { 5 | public string? Id { get; set; } 6 | public string? CompanyName { get; set; } 7 | public string? ContactName { get; set; } 8 | public string? ContactTitle { get; set; } 9 | public string? Address { get; set; } 10 | public string? City { get; set; } 11 | public string? Region { get; set; } 12 | public string? PostalCode { get; set; } 13 | public string? Country { get; set; } 14 | public string? Phone { get; set; } 15 | public List? Orders {get; set;} 16 | } -------------------------------------------------------------------------------- /CosmosDB/Models/Employee.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Models; 2 | 3 | public class Employee 4 | { 5 | public string? Id { get; set; } 6 | public string? FirstName { get; set; } 7 | public string? LastName { get; set; } 8 | public string? Title { get; set; } 9 | public DateTime? BirthDate { get; set; } 10 | public DateTime? HireDate { get; set; } 11 | public string? Address { get; set; } 12 | public string? City { get; set; } 13 | public string? PostalCode { get; set; } 14 | public string? Country { get; set; } 15 | public string? HomePhone { get; set; } 16 | } -------------------------------------------------------------------------------- /CosmosDB/Models/Order.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Models; 2 | 3 | public class Order 4 | { 5 | public string? Id { get; set; } 6 | public DateTime? OrderDate { get; set; } 7 | public DateTime? RequiredDate { get; set; } 8 | public DateTime? ShippedDate { get; set; } 9 | public int? ShipVia { get; set; } 10 | public double? Freight { get; set; } 11 | public string? ShipName { get; set; } 12 | public string? ShipAddress { get; set; } 13 | public string? ShipCity { get; set; } 14 | public string? ShipRegion { get; set; } 15 | public string? ShipPostalCode { get; set; } 16 | public string? ShipCountry { get; set; } 17 | } -------------------------------------------------------------------------------- /CosmosDB/Northwind.CosmosDB.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /CosmosDB/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Northwind.Data; 3 | using Northwind.Models; 4 | 5 | using (var northwindContext = new NorthwindContext()) 6 | { 7 | 8 | #region Inserting Employees 9 | 10 | var employee1 = new Employee() 11 | { 12 | Id = Guid.NewGuid().ToString(), 13 | LastName = "Davolio", 14 | FirstName = "Nancy", 15 | Title = "Sales Representative", 16 | BirthDate = new DateTime(1948, 12, 08), 17 | HireDate = new DateTime(1992, 05, 01), 18 | Address = "507 - 20th Ave. E. Apt. 2A", 19 | City = "Seattle", 20 | PostalCode = "98122", 21 | Country = "USA", 22 | HomePhone = "(206) 555-9857" 23 | }; 24 | 25 | var employee2 = new Employee() 26 | { 27 | Id = Guid.NewGuid().ToString(), 28 | LastName = "Smith", 29 | FirstName = "John", 30 | Title = "Human Resource", 31 | BirthDate = new DateTime(1948, 12, 08), 32 | HireDate = new DateTime(2001, 12, 01), 33 | Address = "507 - 20th Ave. E. Apt. 2A", 34 | City = "Columbia", 35 | PostalCode = "98122", 36 | Country = "USA", 37 | HomePhone = "(204) 551-9857" 38 | }; 39 | 40 | northwindContext.Employees?.Add(employee1); 41 | northwindContext.Employees?.Add(employee2); 42 | 43 | await northwindContext.SaveChangesAsync(); 44 | 45 | Console.WriteLine("Employee records inserted successfully..."); 46 | 47 | #endregion 48 | 49 | #region Inserting Customer 50 | 51 | Customer customer = new Customer() 52 | { 53 | Id = Guid.NewGuid().ToString(), 54 | CompanyName = "Alfreds Futterkiste", 55 | ContactName = "Maria Anders", 56 | ContactTitle = "Sales Representative", 57 | Address = "Obere Str. 57", 58 | City = "Berlin", 59 | Region = null, 60 | PostalCode = "12209", 61 | Country = "Germany", 62 | Phone = "030-0074321", 63 | Orders = new List() 64 | { 65 | new Order() 66 | { 67 | Id = Guid.NewGuid().ToString(), 68 | OrderDate = new DateTime(1997,08,25), 69 | RequiredDate = new DateTime(1997,09,22), 70 | ShippedDate = new DateTime(1997,09,02), 71 | ShipVia = 1, 72 | Freight = 29.46, 73 | ShipName = "Alfreds Futterkiste", 74 | ShipAddress = "Obere Str. 57", 75 | ShipCity = "Berlin", 76 | ShipRegion = null, 77 | ShipPostalCode = "12209", 78 | ShipCountry = "Germany" 79 | }, 80 | new Order() 81 | { 82 | 83 | Id = Guid.NewGuid().ToString(), 84 | OrderDate = new DateTime(1997,10,03), 85 | RequiredDate = new DateTime(1997,10,31), 86 | ShippedDate = new DateTime(1997,10,13), 87 | ShipVia = 2, 88 | Freight = 61.02, 89 | ShipName = "Alfred's Futterkiste", 90 | ShipAddress = "Obere Str. 57", 91 | ShipCity = "Berlin", 92 | ShipRegion = null, 93 | ShipPostalCode = "12209", 94 | ShipCountry = "Germany" 95 | }, 96 | new Order() 97 | { 98 | Id= Guid.NewGuid().ToString(), 99 | OrderDate = new DateTime(1997,10,13), 100 | RequiredDate = new DateTime(1997,11,24), 101 | ShippedDate = new DateTime(1997,10,21), 102 | ShipVia = 1, 103 | Freight = 23.94, 104 | ShipName = "Alfred's Futterkiste", 105 | ShipAddress = "Obere Str. 57", 106 | ShipCity = "Berlin", 107 | ShipRegion = null, 108 | ShipPostalCode = "12209", 109 | ShipCountry = "Germany", 110 | } 111 | } 112 | }; 113 | 114 | northwindContext.Customers?.Add(customer); 115 | await northwindContext.SaveChangesAsync(); 116 | 117 | Console.WriteLine("Customer record inserted successfully..."); 118 | 119 | #endregion 120 | 121 | #region Get Employees 122 | 123 | if(northwindContext.Employees != null) 124 | { 125 | var employees = await northwindContext.Employees.ToListAsync(); 126 | Console.WriteLine(""); 127 | 128 | foreach (var employee in employees) 129 | { 130 | Console.WriteLine("First Name : " + employee.FirstName); 131 | Console.WriteLine("Last Name : " + employee.LastName); 132 | Console.WriteLine("Hire Date : " + employee.HireDate); 133 | Console.WriteLine("--------------------------------\n"); 134 | } 135 | } 136 | 137 | #endregion 138 | 139 | #region Get an Employee 140 | 141 | if (northwindContext.Employees != null) 142 | { 143 | var employee = await northwindContext.Employees 144 | .Where(e => e.FirstName == "John") 145 | .FirstOrDefaultAsync(); 146 | 147 | Console.WriteLine(""); 148 | 149 | Console.WriteLine("First Name : " + employee?.FirstName); 150 | Console.WriteLine("Last Name : " + employee?.LastName); 151 | Console.WriteLine("Hire Date : " + employee?.HireDate); 152 | Console.WriteLine("--------------------------------\n"); 153 | } 154 | 155 | #endregion 156 | 157 | #region Update an Employee 158 | 159 | if (northwindContext.Employees != null) 160 | { 161 | var employee = await northwindContext.Employees 162 | .Where(e => e.FirstName == "John") 163 | .FirstOrDefaultAsync(); 164 | 165 | if(employee != null) 166 | { 167 | employee.LastName = "Doe"; 168 | employee.HireDate = new DateTime(2002,12,01); 169 | 170 | await northwindContext.SaveChangesAsync(); 171 | 172 | Console.WriteLine("\nRecord has been updated.\n"); 173 | } 174 | } 175 | 176 | #endregion 177 | 178 | #region Delete an Employee 179 | 180 | if (northwindContext.Employees != null) 181 | { 182 | var employee = await northwindContext.Employees 183 | .Where(e => e.FirstName == "John") 184 | .FirstOrDefaultAsync(); 185 | 186 | if(employee != null) 187 | { 188 | northwindContext.Employees.Remove(employee); 189 | await northwindContext.SaveChangesAsync(); 190 | 191 | Console.WriteLine("\nRecord has been deleted.\n"); 192 | } 193 | } 194 | 195 | #endregion 196 | 197 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Curious Drive 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MS SQL Server/Database/Loading Related Data.sql: -------------------------------------------------------------------------------- 1 | select c.CustomerID, o.* from Customers c 2 | inner join Orders o on o.CustomerID = c.CustomerID 3 | where c.CustomerID = 'ALFKI' 4 | 5 | -- Order Id - 10248 -------------------------------------------------------------------------------- /MS SQL Server/Database/Northwind.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CuriousDrive/EFCore.AllDatabasesConsidered/467f5253fb2d02a043f76a8033fc56e984ff60c0/MS SQL Server/Database/Northwind.bak -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Controllers/CustomersController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.EntityFrameworkCore; 8 | using Northwind.MSSQL.Data; 9 | using Northwind.MSSQL.Models; 10 | 11 | namespace Northwind.MSSQL.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class CustomersController : ControllerBase 16 | { 17 | private readonly NorthwindContext _context; 18 | 19 | public CustomersController(NorthwindContext context) 20 | { 21 | _context = context; 22 | } 23 | 24 | // GET: api/Customers 25 | [HttpGet] 26 | public async Task>> GetCustomers() 27 | { 28 | return await _context.Customers.ToListAsync(); 29 | } 30 | 31 | // GET: api/Customers/5 32 | [HttpGet("{id}")] 33 | public async Task> GetCustomer(string id) 34 | { 35 | var customer = await _context.Customers.FindAsync(id); 36 | 37 | if (customer == null) 38 | { 39 | return NotFound(); 40 | } 41 | 42 | return customer; 43 | } 44 | 45 | // PUT: api/Customers/5 46 | // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 47 | [HttpPut("{id}")] 48 | public async Task PutCustomer(string id, Customer customer) 49 | { 50 | if (id != customer.CustomerId) 51 | { 52 | return BadRequest(); 53 | } 54 | 55 | _context.Entry(customer).State = EntityState.Modified; 56 | 57 | try 58 | { 59 | await _context.SaveChangesAsync(); 60 | } 61 | catch (DbUpdateConcurrencyException) 62 | { 63 | if (!CustomerExists(id)) 64 | { 65 | return NotFound(); 66 | } 67 | else 68 | { 69 | throw; 70 | } 71 | } 72 | 73 | return NoContent(); 74 | } 75 | 76 | // POST: api/Customers 77 | // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 78 | [HttpPost] 79 | public async Task> PostCustomer(Customer customer) 80 | { 81 | _context.Customers.Add(customer); 82 | try 83 | { 84 | await _context.SaveChangesAsync(); 85 | } 86 | catch (DbUpdateException) 87 | { 88 | if (CustomerExists(customer.CustomerId)) 89 | { 90 | return Conflict(); 91 | } 92 | else 93 | { 94 | throw; 95 | } 96 | } 97 | 98 | return CreatedAtAction("GetCustomer", new { id = customer.CustomerId }, customer); 99 | } 100 | 101 | // DELETE: api/Customers/5 102 | [HttpDelete("{id}")] 103 | public async Task DeleteCustomer(string id) 104 | { 105 | var customer = await _context.Customers.FindAsync(id); 106 | if (customer == null) 107 | { 108 | return NotFound(); 109 | } 110 | 111 | _context.Customers.Remove(customer); 112 | await _context.SaveChangesAsync(); 113 | 114 | return NoContent(); 115 | } 116 | 117 | private bool CustomerExists(string id) 118 | { 119 | return _context.Customers.Any(e => e.CustomerId == id); 120 | } 121 | 122 | //Loading related data 123 | [HttpGet("GetCustomerOrders")] 124 | public async Task> GetCustomerOrders(string customerId) 125 | { 126 | var customer = await _context.Customers 127 | .Where(c => c.CustomerId == customerId) 128 | .Include(c => c.Orders) 129 | .FirstOrDefaultAsync(); 130 | 131 | return customer == null ? NotFound() : customer; 132 | } 133 | 134 | //Loading data from stored procedure - 10248 135 | [HttpGet("CustOrdersDetailAsync")] 136 | public async Task> CustOrdersDetailAsync(int? orderId) 137 | { 138 | return await _context.GetProcedures().CustOrdersDetailAsync(orderId); 139 | } 140 | 141 | //Loading data from a view 142 | [HttpGet("CustomerAndSuppliersByCity")] 143 | public async Task> CustomerAndSuppliersByCity() 144 | { 145 | return await _context.CustomerAndSuppliersByCities.ToListAsync(); 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace Northwind.MSSQL.Controllers 4 | { 5 | [ApiController] 6 | [Route("[controller]")] 7 | public class WeatherForecastController : ControllerBase 8 | { 9 | private static readonly string[] Summaries = new[] 10 | { 11 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 12 | }; 13 | 14 | private readonly ILogger _logger; 15 | 16 | public WeatherForecastController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | [HttpGet(Name = "GetWeatherForecast")] 22 | public IEnumerable Get() 23 | { 24 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 25 | { 26 | Date = DateTime.Now.AddDays(index), 27 | TemperatureC = Random.Shared.Next(-20, 55), 28 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 29 | }) 30 | .ToArray(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Data/DbContextExtensions.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Storage; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Data.Common; 8 | using System.Linq; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | 12 | namespace Northwind.MSSQL.Data 13 | { 14 | public static class DbContextExtensions 15 | { 16 | public static async Task> SqlQueryAsync(this DbContext db, string sql, object[] parameters = null, CancellationToken cancellationToken = default) where T : class 17 | { 18 | if (parameters is null) 19 | { 20 | parameters = new object[] { }; 21 | } 22 | 23 | if (typeof(T).GetProperties().Any()) 24 | { 25 | using (var db2 = new ContextForQueryType(db.Database.GetDbConnection(), db.Database.CurrentTransaction)) 26 | { 27 | db2.Database.SetCommandTimeout(db.Database.GetCommandTimeout()); 28 | return await db2.Set().FromSqlRaw(sql, parameters).ToListAsync(cancellationToken); 29 | } 30 | } 31 | else 32 | { 33 | await db.Database.ExecuteSqlRawAsync(sql, parameters, cancellationToken); 34 | return default; 35 | } 36 | } 37 | 38 | private class ContextForQueryType : DbContext where T : class 39 | { 40 | private readonly DbConnection connection; 41 | private readonly IDbContextTransaction transaction; 42 | 43 | public ContextForQueryType(DbConnection connection, IDbContextTransaction tran) 44 | { 45 | this.connection = connection; 46 | this.transaction = tran; 47 | 48 | if (tran != null) 49 | { 50 | this.Database.UseTransaction((tran as IInfrastructure).Instance); 51 | } 52 | } 53 | 54 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 55 | { 56 | if (transaction != null) 57 | { 58 | optionsBuilder.UseSqlServer(connection); 59 | } 60 | else 61 | { 62 | optionsBuilder.UseSqlServer(connection, options => options.EnableRetryOnFailure()); 63 | } 64 | } 65 | 66 | protected override void OnModelCreating(ModelBuilder modelBuilder) 67 | { 68 | modelBuilder.Entity().HasNoKey().ToView(null); 69 | } 70 | } 71 | } 72 | 73 | public class OutputParameter 74 | { 75 | private bool _valueSet = false; 76 | 77 | public TValue _value; 78 | 79 | public TValue Value 80 | { 81 | get 82 | { 83 | if (!_valueSet) 84 | throw new InvalidOperationException("Value not set."); 85 | 86 | return _value; 87 | } 88 | } 89 | 90 | internal void SetValue(object value) 91 | { 92 | _valueSet = true; 93 | 94 | _value = null == value || Convert.IsDBNull(value) ? default(TValue) : (TValue)value; 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Data/NorthwindContext.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Metadata; 6 | using Northwind.MSSQL.Models; 7 | 8 | namespace Northwind.MSSQL.Data 9 | { 10 | public partial class NorthwindContext : DbContext 11 | { 12 | public NorthwindContext() 13 | { 14 | } 15 | 16 | public NorthwindContext(DbContextOptions options) 17 | : base(options) 18 | { 19 | } 20 | 21 | public virtual DbSet AlphabeticalListOfProducts { get; set; } 22 | public virtual DbSet Categories { get; set; } 23 | public virtual DbSet CategorySalesFor1997s { get; set; } 24 | public virtual DbSet CurrentProductLists { get; set; } 25 | public virtual DbSet Customers { get; set; } 26 | public virtual DbSet CustomerAndSuppliersByCities { get; set; } 27 | public virtual DbSet Employees { get; set; } 28 | public virtual DbSet Invoices { get; set; } 29 | public virtual DbSet Orders { get; set; } 30 | public virtual DbSet OrderDetails { get; set; } 31 | public virtual DbSet OrderDetailsExtendeds { get; set; } 32 | public virtual DbSet OrderSubtotals { get; set; } 33 | public virtual DbSet OrdersQries { get; set; } 34 | public virtual DbSet Products { get; set; } 35 | public virtual DbSet ProductSalesFor1997s { get; set; } 36 | public virtual DbSet ProductsAboveAveragePrices { get; set; } 37 | public virtual DbSet ProductsByCategories { get; set; } 38 | public virtual DbSet QuarterlyOrders { get; set; } 39 | public virtual DbSet SalesByCategories { get; set; } 40 | public virtual DbSet SalesTotalsByAmounts { get; set; } 41 | public virtual DbSet Shippers { get; set; } 42 | public virtual DbSet SummaryOfSalesByQuarters { get; set; } 43 | public virtual DbSet SummaryOfSalesByYears { get; set; } 44 | public virtual DbSet Suppliers { get; set; } 45 | 46 | protected override void OnModelCreating(ModelBuilder modelBuilder) 47 | { 48 | modelBuilder.Entity(entity => 49 | { 50 | entity.HasNoKey(); 51 | 52 | entity.ToView("Alphabetical list of products"); 53 | 54 | entity.Property(e => e.CategoryId).HasColumnName("CategoryID"); 55 | 56 | entity.Property(e => e.CategoryName) 57 | .IsRequired() 58 | .HasMaxLength(15); 59 | 60 | entity.Property(e => e.ProductId).HasColumnName("ProductID"); 61 | 62 | entity.Property(e => e.ProductName) 63 | .IsRequired() 64 | .HasMaxLength(40); 65 | 66 | entity.Property(e => e.QuantityPerUnit).HasMaxLength(20); 67 | 68 | entity.Property(e => e.SupplierId).HasColumnName("SupplierID"); 69 | 70 | entity.Property(e => e.UnitPrice).HasColumnType("money"); 71 | }); 72 | 73 | modelBuilder.Entity(entity => 74 | { 75 | entity.HasIndex(e => e.CategoryName, "CategoryName"); 76 | 77 | entity.Property(e => e.CategoryId).HasColumnName("CategoryID"); 78 | 79 | entity.Property(e => e.CategoryName) 80 | .IsRequired() 81 | .HasMaxLength(15); 82 | 83 | entity.Property(e => e.Description).HasColumnType("ntext"); 84 | 85 | entity.Property(e => e.Picture).HasColumnType("image"); 86 | }); 87 | 88 | modelBuilder.Entity(entity => 89 | { 90 | entity.HasNoKey(); 91 | 92 | entity.ToView("Category Sales for 1997"); 93 | 94 | entity.Property(e => e.CategoryName) 95 | .IsRequired() 96 | .HasMaxLength(15); 97 | 98 | entity.Property(e => e.CategorySales).HasColumnType("money"); 99 | }); 100 | 101 | modelBuilder.Entity(entity => 102 | { 103 | entity.HasNoKey(); 104 | 105 | entity.ToView("Current Product List"); 106 | 107 | entity.Property(e => e.ProductId) 108 | .ValueGeneratedOnAdd() 109 | .HasColumnName("ProductID"); 110 | 111 | entity.Property(e => e.ProductName) 112 | .IsRequired() 113 | .HasMaxLength(40); 114 | }); 115 | 116 | modelBuilder.Entity(entity => 117 | { 118 | entity.HasIndex(e => e.City, "City"); 119 | 120 | entity.HasIndex(e => e.CompanyName, "CompanyName"); 121 | 122 | entity.HasIndex(e => e.PostalCode, "PostalCode"); 123 | 124 | entity.HasIndex(e => e.Region, "Region"); 125 | 126 | entity.Property(e => e.CustomerId) 127 | .HasMaxLength(5) 128 | .HasColumnName("CustomerID") 129 | .IsFixedLength(); 130 | 131 | entity.Property(e => e.Address).HasMaxLength(60); 132 | 133 | entity.Property(e => e.City).HasMaxLength(15); 134 | 135 | entity.Property(e => e.CompanyName) 136 | .IsRequired() 137 | .HasMaxLength(40); 138 | 139 | entity.Property(e => e.ContactName).HasMaxLength(30); 140 | 141 | entity.Property(e => e.ContactTitle).HasMaxLength(30); 142 | 143 | entity.Property(e => e.Country).HasMaxLength(15); 144 | 145 | entity.Property(e => e.Fax).HasMaxLength(24); 146 | 147 | entity.Property(e => e.Phone).HasMaxLength(24); 148 | 149 | entity.Property(e => e.PostalCode).HasMaxLength(10); 150 | 151 | entity.Property(e => e.Region).HasMaxLength(15); 152 | }); 153 | 154 | modelBuilder.Entity(entity => 155 | { 156 | entity.HasNoKey(); 157 | 158 | entity.ToView("Customer and Suppliers by City"); 159 | 160 | entity.Property(e => e.City).HasMaxLength(15); 161 | 162 | entity.Property(e => e.CompanyName) 163 | .IsRequired() 164 | .HasMaxLength(40); 165 | 166 | entity.Property(e => e.ContactName).HasMaxLength(30); 167 | 168 | entity.Property(e => e.Relationship) 169 | .IsRequired() 170 | .HasMaxLength(9) 171 | .IsUnicode(false); 172 | }); 173 | 174 | modelBuilder.Entity(entity => 175 | { 176 | entity.HasIndex(e => e.LastName, "LastName"); 177 | 178 | entity.HasIndex(e => e.PostalCode, "PostalCode"); 179 | 180 | entity.Property(e => e.EmployeeId).HasColumnName("EmployeeID"); 181 | 182 | entity.Property(e => e.Address).HasMaxLength(60); 183 | 184 | entity.Property(e => e.BirthDate).HasColumnType("datetime"); 185 | 186 | entity.Property(e => e.City).HasMaxLength(15); 187 | 188 | entity.Property(e => e.Country).HasMaxLength(15); 189 | 190 | entity.Property(e => e.Extension).HasMaxLength(4); 191 | 192 | entity.Property(e => e.FirstName) 193 | .IsRequired() 194 | .HasMaxLength(10); 195 | 196 | entity.Property(e => e.HireDate).HasColumnType("datetime"); 197 | 198 | entity.Property(e => e.HomePhone).HasMaxLength(24); 199 | 200 | entity.Property(e => e.LastName) 201 | .IsRequired() 202 | .HasMaxLength(20); 203 | 204 | entity.Property(e => e.Notes).HasColumnType("ntext"); 205 | 206 | entity.Property(e => e.Photo).HasColumnType("image"); 207 | 208 | entity.Property(e => e.PhotoPath).HasMaxLength(255); 209 | 210 | entity.Property(e => e.PostalCode).HasMaxLength(10); 211 | 212 | entity.Property(e => e.Region).HasMaxLength(15); 213 | 214 | entity.Property(e => e.Title).HasMaxLength(30); 215 | 216 | entity.Property(e => e.TitleOfCourtesy).HasMaxLength(25); 217 | 218 | entity.HasOne(d => d.ReportsToNavigation) 219 | .WithMany(p => p.InverseReportsToNavigation) 220 | .HasForeignKey(d => d.ReportsTo) 221 | .HasConstraintName("FK_Employees_Employees"); 222 | }); 223 | 224 | modelBuilder.Entity(entity => 225 | { 226 | entity.HasNoKey(); 227 | 228 | entity.ToView("Invoices"); 229 | 230 | entity.Property(e => e.Address).HasMaxLength(60); 231 | 232 | entity.Property(e => e.City).HasMaxLength(15); 233 | 234 | entity.Property(e => e.Country).HasMaxLength(15); 235 | 236 | entity.Property(e => e.CustomerId) 237 | .HasMaxLength(5) 238 | .HasColumnName("CustomerID") 239 | .IsFixedLength(); 240 | 241 | entity.Property(e => e.CustomerName) 242 | .IsRequired() 243 | .HasMaxLength(40); 244 | 245 | entity.Property(e => e.ExtendedPrice).HasColumnType("money"); 246 | 247 | entity.Property(e => e.Freight).HasColumnType("money"); 248 | 249 | entity.Property(e => e.OrderDate).HasColumnType("datetime"); 250 | 251 | entity.Property(e => e.OrderId).HasColumnName("OrderID"); 252 | 253 | entity.Property(e => e.PostalCode).HasMaxLength(10); 254 | 255 | entity.Property(e => e.ProductId).HasColumnName("ProductID"); 256 | 257 | entity.Property(e => e.ProductName) 258 | .IsRequired() 259 | .HasMaxLength(40); 260 | 261 | entity.Property(e => e.Region).HasMaxLength(15); 262 | 263 | entity.Property(e => e.RequiredDate).HasColumnType("datetime"); 264 | 265 | entity.Property(e => e.Salesperson) 266 | .IsRequired() 267 | .HasMaxLength(31); 268 | 269 | entity.Property(e => e.ShipAddress).HasMaxLength(60); 270 | 271 | entity.Property(e => e.ShipCity).HasMaxLength(15); 272 | 273 | entity.Property(e => e.ShipCountry).HasMaxLength(15); 274 | 275 | entity.Property(e => e.ShipName).HasMaxLength(40); 276 | 277 | entity.Property(e => e.ShipPostalCode).HasMaxLength(10); 278 | 279 | entity.Property(e => e.ShipRegion).HasMaxLength(15); 280 | 281 | entity.Property(e => e.ShippedDate).HasColumnType("datetime"); 282 | 283 | entity.Property(e => e.ShipperName) 284 | .IsRequired() 285 | .HasMaxLength(40); 286 | 287 | entity.Property(e => e.UnitPrice).HasColumnType("money"); 288 | }); 289 | 290 | modelBuilder.Entity(entity => 291 | { 292 | entity.HasIndex(e => e.CustomerId, "CustomerID"); 293 | 294 | entity.HasIndex(e => e.CustomerId, "CustomersOrders"); 295 | 296 | entity.HasIndex(e => e.EmployeeId, "EmployeeID"); 297 | 298 | entity.HasIndex(e => e.EmployeeId, "EmployeesOrders"); 299 | 300 | entity.HasIndex(e => e.OrderDate, "OrderDate"); 301 | 302 | entity.HasIndex(e => e.ShipPostalCode, "ShipPostalCode"); 303 | 304 | entity.HasIndex(e => e.ShippedDate, "ShippedDate"); 305 | 306 | entity.HasIndex(e => e.ShipVia, "ShippersOrders"); 307 | 308 | entity.Property(e => e.OrderId).HasColumnName("OrderID"); 309 | 310 | entity.Property(e => e.CustomerId) 311 | .HasMaxLength(5) 312 | .HasColumnName("CustomerID") 313 | .IsFixedLength(); 314 | 315 | entity.Property(e => e.EmployeeId).HasColumnName("EmployeeID"); 316 | 317 | entity.Property(e => e.Freight) 318 | .HasColumnType("money") 319 | .HasDefaultValueSql("((0))"); 320 | 321 | entity.Property(e => e.OrderDate).HasColumnType("datetime"); 322 | 323 | entity.Property(e => e.RequiredDate).HasColumnType("datetime"); 324 | 325 | entity.Property(e => e.ShipAddress).HasMaxLength(60); 326 | 327 | entity.Property(e => e.ShipCity).HasMaxLength(15); 328 | 329 | entity.Property(e => e.ShipCountry).HasMaxLength(15); 330 | 331 | entity.Property(e => e.ShipName).HasMaxLength(40); 332 | 333 | entity.Property(e => e.ShipPostalCode).HasMaxLength(10); 334 | 335 | entity.Property(e => e.ShipRegion).HasMaxLength(15); 336 | 337 | entity.Property(e => e.ShippedDate).HasColumnType("datetime"); 338 | 339 | entity.HasOne(d => d.Customer) 340 | .WithMany(p => p.Orders) 341 | .HasForeignKey(d => d.CustomerId) 342 | .HasConstraintName("FK_Orders_Customers"); 343 | 344 | entity.HasOne(d => d.Employee) 345 | .WithMany(p => p.Orders) 346 | .HasForeignKey(d => d.EmployeeId) 347 | .HasConstraintName("FK_Orders_Employees"); 348 | 349 | entity.HasOne(d => d.ShipViaNavigation) 350 | .WithMany(p => p.Orders) 351 | .HasForeignKey(d => d.ShipVia) 352 | .HasConstraintName("FK_Orders_Shippers"); 353 | }); 354 | 355 | modelBuilder.Entity(entity => 356 | { 357 | entity.HasKey(e => new { e.OrderId, e.ProductId }) 358 | .HasName("PK_Order_Details"); 359 | 360 | entity.ToTable("Order Details"); 361 | 362 | entity.HasIndex(e => e.OrderId, "OrderID"); 363 | 364 | entity.HasIndex(e => e.OrderId, "OrdersOrder_Details"); 365 | 366 | entity.HasIndex(e => e.ProductId, "ProductID"); 367 | 368 | entity.HasIndex(e => e.ProductId, "ProductsOrder_Details"); 369 | 370 | entity.Property(e => e.OrderId).HasColumnName("OrderID"); 371 | 372 | entity.Property(e => e.ProductId).HasColumnName("ProductID"); 373 | 374 | entity.Property(e => e.Quantity).HasDefaultValueSql("((1))"); 375 | 376 | entity.Property(e => e.UnitPrice).HasColumnType("money"); 377 | 378 | entity.HasOne(d => d.Order) 379 | .WithMany(p => p.OrderDetails) 380 | .HasForeignKey(d => d.OrderId) 381 | .OnDelete(DeleteBehavior.ClientSetNull) 382 | .HasConstraintName("FK_Order_Details_Orders"); 383 | 384 | entity.HasOne(d => d.Product) 385 | .WithMany(p => p.OrderDetails) 386 | .HasForeignKey(d => d.ProductId) 387 | .OnDelete(DeleteBehavior.ClientSetNull) 388 | .HasConstraintName("FK_Order_Details_Products"); 389 | }); 390 | 391 | modelBuilder.Entity(entity => 392 | { 393 | entity.HasNoKey(); 394 | 395 | entity.ToView("Order Details Extended"); 396 | 397 | entity.Property(e => e.ExtendedPrice).HasColumnType("money"); 398 | 399 | entity.Property(e => e.OrderId).HasColumnName("OrderID"); 400 | 401 | entity.Property(e => e.ProductId).HasColumnName("ProductID"); 402 | 403 | entity.Property(e => e.ProductName) 404 | .IsRequired() 405 | .HasMaxLength(40); 406 | 407 | entity.Property(e => e.UnitPrice).HasColumnType("money"); 408 | }); 409 | 410 | modelBuilder.Entity(entity => 411 | { 412 | entity.HasNoKey(); 413 | 414 | entity.ToView("Order Subtotals"); 415 | 416 | entity.Property(e => e.OrderId).HasColumnName("OrderID"); 417 | 418 | entity.Property(e => e.Subtotal).HasColumnType("money"); 419 | }); 420 | 421 | modelBuilder.Entity(entity => 422 | { 423 | entity.HasNoKey(); 424 | 425 | entity.ToView("Orders Qry"); 426 | 427 | entity.Property(e => e.Address).HasMaxLength(60); 428 | 429 | entity.Property(e => e.City).HasMaxLength(15); 430 | 431 | entity.Property(e => e.CompanyName) 432 | .IsRequired() 433 | .HasMaxLength(40); 434 | 435 | entity.Property(e => e.Country).HasMaxLength(15); 436 | 437 | entity.Property(e => e.CustomerId) 438 | .HasMaxLength(5) 439 | .HasColumnName("CustomerID") 440 | .IsFixedLength(); 441 | 442 | entity.Property(e => e.EmployeeId).HasColumnName("EmployeeID"); 443 | 444 | entity.Property(e => e.Freight).HasColumnType("money"); 445 | 446 | entity.Property(e => e.OrderDate).HasColumnType("datetime"); 447 | 448 | entity.Property(e => e.OrderId).HasColumnName("OrderID"); 449 | 450 | entity.Property(e => e.PostalCode).HasMaxLength(10); 451 | 452 | entity.Property(e => e.Region).HasMaxLength(15); 453 | 454 | entity.Property(e => e.RequiredDate).HasColumnType("datetime"); 455 | 456 | entity.Property(e => e.ShipAddress).HasMaxLength(60); 457 | 458 | entity.Property(e => e.ShipCity).HasMaxLength(15); 459 | 460 | entity.Property(e => e.ShipCountry).HasMaxLength(15); 461 | 462 | entity.Property(e => e.ShipName).HasMaxLength(40); 463 | 464 | entity.Property(e => e.ShipPostalCode).HasMaxLength(10); 465 | 466 | entity.Property(e => e.ShipRegion).HasMaxLength(15); 467 | 468 | entity.Property(e => e.ShippedDate).HasColumnType("datetime"); 469 | }); 470 | 471 | modelBuilder.Entity(entity => 472 | { 473 | entity.HasIndex(e => e.CategoryId, "CategoriesProducts"); 474 | 475 | entity.HasIndex(e => e.CategoryId, "CategoryID"); 476 | 477 | entity.HasIndex(e => e.ProductName, "ProductName"); 478 | 479 | entity.HasIndex(e => e.SupplierId, "SupplierID"); 480 | 481 | entity.HasIndex(e => e.SupplierId, "SuppliersProducts"); 482 | 483 | entity.Property(e => e.ProductId).HasColumnName("ProductID"); 484 | 485 | entity.Property(e => e.CategoryId).HasColumnName("CategoryID"); 486 | 487 | entity.Property(e => e.ProductName) 488 | .IsRequired() 489 | .HasMaxLength(40); 490 | 491 | entity.Property(e => e.QuantityPerUnit).HasMaxLength(20); 492 | 493 | entity.Property(e => e.ReorderLevel).HasDefaultValueSql("((0))"); 494 | 495 | entity.Property(e => e.SupplierId).HasColumnName("SupplierID"); 496 | 497 | entity.Property(e => e.UnitPrice) 498 | .HasColumnType("money") 499 | .HasDefaultValueSql("((0))"); 500 | 501 | entity.Property(e => e.UnitsInStock).HasDefaultValueSql("((0))"); 502 | 503 | entity.Property(e => e.UnitsOnOrder).HasDefaultValueSql("((0))"); 504 | 505 | entity.HasOne(d => d.Category) 506 | .WithMany(p => p.Products) 507 | .HasForeignKey(d => d.CategoryId) 508 | .HasConstraintName("FK_Products_Categories"); 509 | 510 | entity.HasOne(d => d.Supplier) 511 | .WithMany(p => p.Products) 512 | .HasForeignKey(d => d.SupplierId) 513 | .HasConstraintName("FK_Products_Suppliers"); 514 | }); 515 | 516 | modelBuilder.Entity(entity => 517 | { 518 | entity.HasNoKey(); 519 | 520 | entity.ToView("Product Sales for 1997"); 521 | 522 | entity.Property(e => e.CategoryName) 523 | .IsRequired() 524 | .HasMaxLength(15); 525 | 526 | entity.Property(e => e.ProductName) 527 | .IsRequired() 528 | .HasMaxLength(40); 529 | 530 | entity.Property(e => e.ProductSales).HasColumnType("money"); 531 | }); 532 | 533 | modelBuilder.Entity(entity => 534 | { 535 | entity.HasNoKey(); 536 | 537 | entity.ToView("Products Above Average Price"); 538 | 539 | entity.Property(e => e.ProductName) 540 | .IsRequired() 541 | .HasMaxLength(40); 542 | 543 | entity.Property(e => e.UnitPrice).HasColumnType("money"); 544 | }); 545 | 546 | modelBuilder.Entity(entity => 547 | { 548 | entity.HasNoKey(); 549 | 550 | entity.ToView("Products by Category"); 551 | 552 | entity.Property(e => e.CategoryName) 553 | .IsRequired() 554 | .HasMaxLength(15); 555 | 556 | entity.Property(e => e.ProductName) 557 | .IsRequired() 558 | .HasMaxLength(40); 559 | 560 | entity.Property(e => e.QuantityPerUnit).HasMaxLength(20); 561 | }); 562 | 563 | modelBuilder.Entity(entity => 564 | { 565 | entity.HasNoKey(); 566 | 567 | entity.ToView("Quarterly Orders"); 568 | 569 | entity.Property(e => e.City).HasMaxLength(15); 570 | 571 | entity.Property(e => e.CompanyName).HasMaxLength(40); 572 | 573 | entity.Property(e => e.Country).HasMaxLength(15); 574 | 575 | entity.Property(e => e.CustomerId) 576 | .HasMaxLength(5) 577 | .HasColumnName("CustomerID") 578 | .IsFixedLength(); 579 | }); 580 | 581 | modelBuilder.Entity(entity => 582 | { 583 | entity.HasNoKey(); 584 | 585 | entity.ToView("Sales by Category"); 586 | 587 | entity.Property(e => e.CategoryId).HasColumnName("CategoryID"); 588 | 589 | entity.Property(e => e.CategoryName) 590 | .IsRequired() 591 | .HasMaxLength(15); 592 | 593 | entity.Property(e => e.ProductName) 594 | .IsRequired() 595 | .HasMaxLength(40); 596 | 597 | entity.Property(e => e.ProductSales).HasColumnType("money"); 598 | }); 599 | 600 | modelBuilder.Entity(entity => 601 | { 602 | entity.HasNoKey(); 603 | 604 | entity.ToView("Sales Totals by Amount"); 605 | 606 | entity.Property(e => e.CompanyName) 607 | .IsRequired() 608 | .HasMaxLength(40); 609 | 610 | entity.Property(e => e.OrderId).HasColumnName("OrderID"); 611 | 612 | entity.Property(e => e.SaleAmount).HasColumnType("money"); 613 | 614 | entity.Property(e => e.ShippedDate).HasColumnType("datetime"); 615 | }); 616 | 617 | modelBuilder.Entity(entity => 618 | { 619 | entity.Property(e => e.ShipperId).HasColumnName("ShipperID"); 620 | 621 | entity.Property(e => e.CompanyName) 622 | .IsRequired() 623 | .HasMaxLength(40); 624 | 625 | entity.Property(e => e.Phone).HasMaxLength(24); 626 | }); 627 | 628 | modelBuilder.Entity(entity => 629 | { 630 | entity.HasNoKey(); 631 | 632 | entity.ToView("Summary of Sales by Quarter"); 633 | 634 | entity.Property(e => e.OrderId).HasColumnName("OrderID"); 635 | 636 | entity.Property(e => e.ShippedDate).HasColumnType("datetime"); 637 | 638 | entity.Property(e => e.Subtotal).HasColumnType("money"); 639 | }); 640 | 641 | modelBuilder.Entity(entity => 642 | { 643 | entity.HasNoKey(); 644 | 645 | entity.ToView("Summary of Sales by Year"); 646 | 647 | entity.Property(e => e.OrderId).HasColumnName("OrderID"); 648 | 649 | entity.Property(e => e.ShippedDate).HasColumnType("datetime"); 650 | 651 | entity.Property(e => e.Subtotal).HasColumnType("money"); 652 | }); 653 | 654 | modelBuilder.Entity(entity => 655 | { 656 | entity.HasIndex(e => e.CompanyName, "CompanyName"); 657 | 658 | entity.HasIndex(e => e.PostalCode, "PostalCode"); 659 | 660 | entity.Property(e => e.SupplierId).HasColumnName("SupplierID"); 661 | 662 | entity.Property(e => e.Address).HasMaxLength(60); 663 | 664 | entity.Property(e => e.City).HasMaxLength(15); 665 | 666 | entity.Property(e => e.CompanyName) 667 | .IsRequired() 668 | .HasMaxLength(40); 669 | 670 | entity.Property(e => e.ContactName).HasMaxLength(30); 671 | 672 | entity.Property(e => e.ContactTitle).HasMaxLength(30); 673 | 674 | entity.Property(e => e.Country).HasMaxLength(15); 675 | 676 | entity.Property(e => e.Fax).HasMaxLength(24); 677 | 678 | entity.Property(e => e.HomePage).HasColumnType("ntext"); 679 | 680 | entity.Property(e => e.Phone).HasMaxLength(24); 681 | 682 | entity.Property(e => e.PostalCode).HasMaxLength(10); 683 | 684 | entity.Property(e => e.Region).HasMaxLength(15); 685 | }); 686 | 687 | OnModelCreatingPartial(modelBuilder); 688 | } 689 | 690 | partial void OnModelCreatingPartial(ModelBuilder modelBuilder); 691 | } 692 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Data/NorthwindContextProcedures.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.Data.SqlClient; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Data; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using Northwind.MSSQL.Models; 10 | 11 | namespace Northwind.MSSQL.Data 12 | { 13 | public partial class NorthwindContext 14 | { 15 | private NorthwindContextProcedures _procedures; 16 | 17 | public virtual NorthwindContextProcedures Procedures 18 | { 19 | get 20 | { 21 | if (_procedures is null) _procedures = new NorthwindContextProcedures(this); 22 | return _procedures; 23 | } 24 | set 25 | { 26 | _procedures = value; 27 | } 28 | } 29 | 30 | public NorthwindContextProcedures GetProcedures() 31 | { 32 | return Procedures; 33 | } 34 | } 35 | 36 | public partial class NorthwindContextProcedures 37 | { 38 | private readonly NorthwindContext _context; 39 | 40 | public NorthwindContextProcedures(NorthwindContext context) 41 | { 42 | _context = context; 43 | } 44 | 45 | public virtual async Task> CustOrderHistAsync(string CustomerID, OutputParameter returnValue = null, CancellationToken cancellationToken = default) 46 | { 47 | var parameterreturnValue = new SqlParameter 48 | { 49 | ParameterName = "returnValue", 50 | Direction = System.Data.ParameterDirection.Output, 51 | SqlDbType = System.Data.SqlDbType.Int, 52 | }; 53 | 54 | var sqlParameters = new [] 55 | { 56 | new SqlParameter 57 | { 58 | ParameterName = "CustomerID", 59 | Size = 10, 60 | Value = CustomerID ?? Convert.DBNull, 61 | SqlDbType = System.Data.SqlDbType.NChar, 62 | }, 63 | parameterreturnValue, 64 | }; 65 | var _ = await _context.SqlQueryAsync("EXEC @returnValue = [dbo].[CustOrderHist] @CustomerID", sqlParameters, cancellationToken); 66 | 67 | returnValue?.SetValue(parameterreturnValue.Value); 68 | 69 | return _; 70 | } 71 | 72 | public virtual async Task> CustOrdersDetailAsync(int? OrderID, OutputParameter returnValue = null, CancellationToken cancellationToken = default) 73 | { 74 | var parameterreturnValue = new SqlParameter 75 | { 76 | ParameterName = "returnValue", 77 | Direction = System.Data.ParameterDirection.Output, 78 | SqlDbType = System.Data.SqlDbType.Int, 79 | }; 80 | 81 | var sqlParameters = new [] 82 | { 83 | new SqlParameter 84 | { 85 | ParameterName = "OrderID", 86 | Value = OrderID ?? Convert.DBNull, 87 | SqlDbType = System.Data.SqlDbType.Int, 88 | }, 89 | parameterreturnValue, 90 | }; 91 | var _ = await _context.SqlQueryAsync("EXEC @returnValue = [dbo].[CustOrdersDetail] @OrderID", sqlParameters, cancellationToken); 92 | 93 | returnValue?.SetValue(parameterreturnValue.Value); 94 | 95 | return _; 96 | } 97 | 98 | public virtual async Task> CustOrdersOrdersAsync(string CustomerID, OutputParameter returnValue = null, CancellationToken cancellationToken = default) 99 | { 100 | var parameterreturnValue = new SqlParameter 101 | { 102 | ParameterName = "returnValue", 103 | Direction = System.Data.ParameterDirection.Output, 104 | SqlDbType = System.Data.SqlDbType.Int, 105 | }; 106 | 107 | var sqlParameters = new [] 108 | { 109 | new SqlParameter 110 | { 111 | ParameterName = "CustomerID", 112 | Size = 10, 113 | Value = CustomerID ?? Convert.DBNull, 114 | SqlDbType = System.Data.SqlDbType.NChar, 115 | }, 116 | parameterreturnValue, 117 | }; 118 | var _ = await _context.SqlQueryAsync("EXEC @returnValue = [dbo].[CustOrdersOrders] @CustomerID", sqlParameters, cancellationToken); 119 | 120 | returnValue?.SetValue(parameterreturnValue.Value); 121 | 122 | return _; 123 | } 124 | 125 | public virtual async Task> EmployeeSalesbyCountryAsync(DateTime? Beginning_Date, DateTime? Ending_Date, OutputParameter returnValue = null, CancellationToken cancellationToken = default) 126 | { 127 | var parameterreturnValue = new SqlParameter 128 | { 129 | ParameterName = "returnValue", 130 | Direction = System.Data.ParameterDirection.Output, 131 | SqlDbType = System.Data.SqlDbType.Int, 132 | }; 133 | 134 | var sqlParameters = new [] 135 | { 136 | new SqlParameter 137 | { 138 | ParameterName = "Beginning_Date", 139 | Value = Beginning_Date ?? Convert.DBNull, 140 | SqlDbType = System.Data.SqlDbType.DateTime, 141 | }, 142 | new SqlParameter 143 | { 144 | ParameterName = "Ending_Date", 145 | Value = Ending_Date ?? Convert.DBNull, 146 | SqlDbType = System.Data.SqlDbType.DateTime, 147 | }, 148 | parameterreturnValue, 149 | }; 150 | var _ = await _context.SqlQueryAsync("EXEC @returnValue = [dbo].[Employee Sales by Country] @Beginning_Date, @Ending_Date", sqlParameters, cancellationToken); 151 | 152 | returnValue?.SetValue(parameterreturnValue.Value); 153 | 154 | return _; 155 | } 156 | 157 | public virtual async Task> SalesbyYearAsync(DateTime? Beginning_Date, DateTime? Ending_Date, OutputParameter returnValue = null, CancellationToken cancellationToken = default) 158 | { 159 | var parameterreturnValue = new SqlParameter 160 | { 161 | ParameterName = "returnValue", 162 | Direction = System.Data.ParameterDirection.Output, 163 | SqlDbType = System.Data.SqlDbType.Int, 164 | }; 165 | 166 | var sqlParameters = new [] 167 | { 168 | new SqlParameter 169 | { 170 | ParameterName = "Beginning_Date", 171 | Value = Beginning_Date ?? Convert.DBNull, 172 | SqlDbType = System.Data.SqlDbType.DateTime, 173 | }, 174 | new SqlParameter 175 | { 176 | ParameterName = "Ending_Date", 177 | Value = Ending_Date ?? Convert.DBNull, 178 | SqlDbType = System.Data.SqlDbType.DateTime, 179 | }, 180 | parameterreturnValue, 181 | }; 182 | var _ = await _context.SqlQueryAsync("EXEC @returnValue = [dbo].[Sales by Year] @Beginning_Date, @Ending_Date", sqlParameters, cancellationToken); 183 | 184 | returnValue?.SetValue(parameterreturnValue.Value); 185 | 186 | return _; 187 | } 188 | 189 | public virtual async Task> SalesByCategoryAsync(string CategoryName, string OrdYear, OutputParameter returnValue = null, CancellationToken cancellationToken = default) 190 | { 191 | var parameterreturnValue = new SqlParameter 192 | { 193 | ParameterName = "returnValue", 194 | Direction = System.Data.ParameterDirection.Output, 195 | SqlDbType = System.Data.SqlDbType.Int, 196 | }; 197 | 198 | var sqlParameters = new [] 199 | { 200 | new SqlParameter 201 | { 202 | ParameterName = "CategoryName", 203 | Size = 30, 204 | Value = CategoryName ?? Convert.DBNull, 205 | SqlDbType = System.Data.SqlDbType.NVarChar, 206 | }, 207 | new SqlParameter 208 | { 209 | ParameterName = "OrdYear", 210 | Size = 8, 211 | Value = OrdYear ?? Convert.DBNull, 212 | SqlDbType = System.Data.SqlDbType.NVarChar, 213 | }, 214 | parameterreturnValue, 215 | }; 216 | var _ = await _context.SqlQueryAsync("EXEC @returnValue = [dbo].[SalesByCategory] @CategoryName, @OrdYear", sqlParameters, cancellationToken); 217 | 218 | returnValue?.SetValue(parameterreturnValue.Value); 219 | 220 | return _; 221 | } 222 | 223 | public virtual async Task> TenMostExpensiveProductsAsync(OutputParameter returnValue = null, CancellationToken cancellationToken = default) 224 | { 225 | var parameterreturnValue = new SqlParameter 226 | { 227 | ParameterName = "returnValue", 228 | Direction = System.Data.ParameterDirection.Output, 229 | SqlDbType = System.Data.SqlDbType.Int, 230 | }; 231 | 232 | var sqlParameters = new [] 233 | { 234 | parameterreturnValue, 235 | }; 236 | var _ = await _context.SqlQueryAsync("EXEC @returnValue = [dbo].[Ten Most Expensive Products]", sqlParameters, cancellationToken); 237 | 238 | returnValue?.SetValue(parameterreturnValue.Value); 239 | 240 | return _; 241 | } 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/AlphabeticalListOfProduct.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class AlphabeticalListOfProduct 8 | { 9 | public int ProductId { get; set; } 10 | public string ProductName { get; set; } 11 | public int? SupplierId { get; set; } 12 | public int? CategoryId { get; set; } 13 | public string QuantityPerUnit { get; set; } 14 | public decimal? UnitPrice { get; set; } 15 | public short? UnitsInStock { get; set; } 16 | public short? UnitsOnOrder { get; set; } 17 | public short? ReorderLevel { get; set; } 18 | public bool Discontinued { get; set; } 19 | public string CategoryName { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/Category.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class Category 8 | { 9 | public Category() 10 | { 11 | Products = new HashSet(); 12 | } 13 | 14 | public int CategoryId { get; set; } 15 | public string CategoryName { get; set; } 16 | public string Description { get; set; } 17 | public byte[] Picture { get; set; } 18 | 19 | public virtual ICollection Products { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/CategorySalesFor1997.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class CategorySalesFor1997 8 | { 9 | public string CategoryName { get; set; } 10 | public decimal? CategorySales { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/CurrentProductList.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class CurrentProductList 8 | { 9 | public int ProductId { get; set; } 10 | public string ProductName { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/CustOrderHistResult.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | namespace Northwind.MSSQL.Models 7 | { 8 | public partial class CustOrderHistResult 9 | { 10 | public string ProductName { get; set; } 11 | public int? Total { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/CustOrdersDetailResult.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | namespace Northwind.MSSQL.Models 7 | { 8 | public partial class CustOrdersDetailResult 9 | { 10 | public string ProductName { get; set; } 11 | public decimal UnitPrice { get; set; } 12 | public short Quantity { get; set; } 13 | public int? Discount { get; set; } 14 | public decimal? ExtendedPrice { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/CustOrdersOrdersResult.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | namespace Northwind.MSSQL.Models 7 | { 8 | public partial class CustOrdersOrdersResult 9 | { 10 | public int OrderID { get; set; } 11 | public DateTime? OrderDate { get; set; } 12 | public DateTime? RequiredDate { get; set; } 13 | public DateTime? ShippedDate { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/Customer.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class Customer 8 | { 9 | public Customer() 10 | { 11 | Orders = new HashSet(); 12 | } 13 | 14 | public string CustomerId { get; set; } 15 | public string CompanyName { get; set; } 16 | public string ContactName { get; set; } 17 | public string ContactTitle { get; set; } 18 | public string Address { get; set; } 19 | public string City { get; set; } 20 | public string Region { get; set; } 21 | public string PostalCode { get; set; } 22 | public string Country { get; set; } 23 | public string Phone { get; set; } 24 | public string Fax { get; set; } 25 | 26 | public virtual ICollection Orders { get; set; } 27 | } 28 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/CustomerAndSuppliersByCity.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class CustomerAndSuppliersByCity 8 | { 9 | public string City { get; set; } 10 | public string CompanyName { get; set; } 11 | public string ContactName { get; set; } 12 | public string Relationship { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/Employee.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class Employee 8 | { 9 | public Employee() 10 | { 11 | InverseReportsToNavigation = new HashSet(); 12 | Orders = new HashSet(); 13 | } 14 | 15 | public int EmployeeId { get; set; } 16 | public string LastName { get; set; } 17 | public string FirstName { get; set; } 18 | public string Title { get; set; } 19 | public string TitleOfCourtesy { get; set; } 20 | public DateTime? BirthDate { get; set; } 21 | public DateTime? HireDate { get; set; } 22 | public string Address { get; set; } 23 | public string City { get; set; } 24 | public string Region { get; set; } 25 | public string PostalCode { get; set; } 26 | public string Country { get; set; } 27 | public string HomePhone { get; set; } 28 | public string Extension { get; set; } 29 | public byte[] Photo { get; set; } 30 | public string Notes { get; set; } 31 | public int? ReportsTo { get; set; } 32 | public string PhotoPath { get; set; } 33 | 34 | public virtual Employee ReportsToNavigation { get; set; } 35 | public virtual ICollection InverseReportsToNavigation { get; set; } 36 | public virtual ICollection Orders { get; set; } 37 | } 38 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/EmployeeSalesbyCountryResult.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | namespace Northwind.MSSQL.Models 7 | { 8 | public partial class EmployeeSalesbyCountryResult 9 | { 10 | public string Country { get; set; } 11 | public string LastName { get; set; } 12 | public string FirstName { get; set; } 13 | public DateTime? ShippedDate { get; set; } 14 | public int OrderID { get; set; } 15 | public decimal? SaleAmount { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/Invoice.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class Invoice 8 | { 9 | public string ShipName { get; set; } 10 | public string ShipAddress { get; set; } 11 | public string ShipCity { get; set; } 12 | public string ShipRegion { get; set; } 13 | public string ShipPostalCode { get; set; } 14 | public string ShipCountry { get; set; } 15 | public string CustomerId { get; set; } 16 | public string CustomerName { get; set; } 17 | public string Address { get; set; } 18 | public string City { get; set; } 19 | public string Region { get; set; } 20 | public string PostalCode { get; set; } 21 | public string Country { get; set; } 22 | public string Salesperson { get; set; } 23 | public int OrderId { get; set; } 24 | public DateTime? OrderDate { get; set; } 25 | public DateTime? RequiredDate { get; set; } 26 | public DateTime? ShippedDate { get; set; } 27 | public string ShipperName { get; set; } 28 | public int ProductId { get; set; } 29 | public string ProductName { get; set; } 30 | public decimal UnitPrice { get; set; } 31 | public short Quantity { get; set; } 32 | public float Discount { get; set; } 33 | public decimal? ExtendedPrice { get; set; } 34 | public decimal? Freight { get; set; } 35 | } 36 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/Order.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class Order 8 | { 9 | public Order() 10 | { 11 | OrderDetails = new HashSet(); 12 | } 13 | 14 | public int OrderId { get; set; } 15 | public string CustomerId { get; set; } 16 | public int? EmployeeId { get; set; } 17 | public DateTime? OrderDate { get; set; } 18 | public DateTime? RequiredDate { get; set; } 19 | public DateTime? ShippedDate { get; set; } 20 | public int? ShipVia { get; set; } 21 | public decimal? Freight { get; set; } 22 | public string ShipName { get; set; } 23 | public string ShipAddress { get; set; } 24 | public string ShipCity { get; set; } 25 | public string ShipRegion { get; set; } 26 | public string ShipPostalCode { get; set; } 27 | public string ShipCountry { get; set; } 28 | 29 | public virtual Customer Customer { get; set; } 30 | public virtual Employee Employee { get; set; } 31 | public virtual Shipper ShipViaNavigation { get; set; } 32 | public virtual ICollection OrderDetails { get; set; } 33 | } 34 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/OrderDetail.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class OrderDetail 8 | { 9 | public int OrderId { get; set; } 10 | public int ProductId { get; set; } 11 | public decimal UnitPrice { get; set; } 12 | public short Quantity { get; set; } 13 | public float Discount { get; set; } 14 | 15 | public virtual Order Order { get; set; } 16 | public virtual Product Product { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/OrderDetailsExtended.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class OrderDetailsExtended 8 | { 9 | public int OrderId { get; set; } 10 | public int ProductId { get; set; } 11 | public string ProductName { get; set; } 12 | public decimal UnitPrice { get; set; } 13 | public short Quantity { get; set; } 14 | public float Discount { get; set; } 15 | public decimal? ExtendedPrice { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/OrderSubtotal.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class OrderSubtotal 8 | { 9 | public int OrderId { get; set; } 10 | public decimal? Subtotal { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/OrdersQry.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class OrdersQry 8 | { 9 | public int OrderId { get; set; } 10 | public string CustomerId { get; set; } 11 | public int? EmployeeId { get; set; } 12 | public DateTime? OrderDate { get; set; } 13 | public DateTime? RequiredDate { get; set; } 14 | public DateTime? ShippedDate { get; set; } 15 | public int? ShipVia { get; set; } 16 | public decimal? Freight { get; set; } 17 | public string ShipName { get; set; } 18 | public string ShipAddress { get; set; } 19 | public string ShipCity { get; set; } 20 | public string ShipRegion { get; set; } 21 | public string ShipPostalCode { get; set; } 22 | public string ShipCountry { get; set; } 23 | public string CompanyName { get; set; } 24 | public string Address { get; set; } 25 | public string City { get; set; } 26 | public string Region { get; set; } 27 | public string PostalCode { get; set; } 28 | public string Country { get; set; } 29 | } 30 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/Product.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class Product 8 | { 9 | public Product() 10 | { 11 | OrderDetails = new HashSet(); 12 | } 13 | 14 | public int ProductId { get; set; } 15 | public string ProductName { get; set; } 16 | public int? SupplierId { get; set; } 17 | public int? CategoryId { get; set; } 18 | public string QuantityPerUnit { get; set; } 19 | public decimal? UnitPrice { get; set; } 20 | public short? UnitsInStock { get; set; } 21 | public short? UnitsOnOrder { get; set; } 22 | public short? ReorderLevel { get; set; } 23 | public bool Discontinued { get; set; } 24 | 25 | public virtual Category Category { get; set; } 26 | public virtual Supplier Supplier { get; set; } 27 | public virtual ICollection OrderDetails { get; set; } 28 | } 29 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/ProductSalesFor1997.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class ProductSalesFor1997 8 | { 9 | public string CategoryName { get; set; } 10 | public string ProductName { get; set; } 11 | public decimal? ProductSales { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/ProductsAboveAveragePrice.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class ProductsAboveAveragePrice 8 | { 9 | public string ProductName { get; set; } 10 | public decimal? UnitPrice { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/ProductsByCategory.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class ProductsByCategory 8 | { 9 | public string CategoryName { get; set; } 10 | public string ProductName { get; set; } 11 | public string QuantityPerUnit { get; set; } 12 | public short? UnitsInStock { get; set; } 13 | public bool Discontinued { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/QuarterlyOrder.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class QuarterlyOrder 8 | { 9 | public string CustomerId { get; set; } 10 | public string CompanyName { get; set; } 11 | public string City { get; set; } 12 | public string Country { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/SalesByCategory.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class SalesByCategory 8 | { 9 | public int CategoryId { get; set; } 10 | public string CategoryName { get; set; } 11 | public string ProductName { get; set; } 12 | public decimal? ProductSales { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/SalesByCategoryResult.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | namespace Northwind.MSSQL.Models 7 | { 8 | public partial class SalesByCategoryResult 9 | { 10 | public string ProductName { get; set; } 11 | public decimal? TotalPurchase { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/SalesTotalsByAmount.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class SalesTotalsByAmount 8 | { 9 | public decimal? SaleAmount { get; set; } 10 | public int OrderId { get; set; } 11 | public string CompanyName { get; set; } 12 | public DateTime? ShippedDate { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/SalesbyYearResult.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | namespace Northwind.MSSQL.Models 7 | { 8 | public partial class SalesbyYearResult 9 | { 10 | public DateTime? ShippedDate { get; set; } 11 | public int OrderID { get; set; } 12 | public decimal? Subtotal { get; set; } 13 | public string Year { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/Shipper.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class Shipper 8 | { 9 | public Shipper() 10 | { 11 | Orders = new HashSet(); 12 | } 13 | 14 | public int ShipperId { get; set; } 15 | public string CompanyName { get; set; } 16 | public string Phone { get; set; } 17 | 18 | public virtual ICollection Orders { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/SummaryOfSalesByQuarter.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class SummaryOfSalesByQuarter 8 | { 9 | public DateTime? ShippedDate { get; set; } 10 | public int OrderId { get; set; } 11 | public decimal? Subtotal { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/SummaryOfSalesByYear.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class SummaryOfSalesByYear 8 | { 9 | public DateTime? ShippedDate { get; set; } 10 | public int OrderId { get; set; } 11 | public decimal? Subtotal { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/Supplier.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.MSSQL.Models 6 | { 7 | public partial class Supplier 8 | { 9 | public Supplier() 10 | { 11 | Products = new HashSet(); 12 | } 13 | 14 | public int SupplierId { get; set; } 15 | public string CompanyName { get; set; } 16 | public string ContactName { get; set; } 17 | public string ContactTitle { get; set; } 18 | public string Address { get; set; } 19 | public string City { get; set; } 20 | public string Region { get; set; } 21 | public string PostalCode { get; set; } 22 | public string Country { get; set; } 23 | public string Phone { get; set; } 24 | public string Fax { get; set; } 25 | public string HomePage { get; set; } 26 | 27 | public virtual ICollection Products { get; set; } 28 | } 29 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Models/TenMostExpensiveProductsResult.cs: -------------------------------------------------------------------------------- 1 | // This file has been auto generated by EF Core Power Tools. 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | 6 | namespace Northwind.MSSQL.Models 7 | { 8 | public partial class TenMostExpensiveProductsResult 9 | { 10 | public string TenMostExpensiveProducts { get; set; } 11 | public decimal? UnitPrice { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Northwind.MSSQL.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | all 12 | runtime; build; native; contentfiles; analyzers; buildtransitive 13 | 14 | 15 | 16 | 17 | all 18 | runtime; build; native; contentfiles; analyzers 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Northwind.MSSQL.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31912.275 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Northwind.MSSQL", "Northwind.MSSQL.csproj", "{97695037-4ECE-4602-9B96-E92E82916C9B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {97695037-4ECE-4602-9B96-E92E82916C9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {97695037-4ECE-4602-9B96-E92E82916C9B}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {97695037-4ECE-4602-9B96-E92E82916C9B}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {97695037-4ECE-4602-9B96-E92E82916C9B}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {D26D5458-FFAE-4591-A8C5-1E131ACF03EE} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Newtonsoft.Json; 3 | 4 | var builder = WebApplication.CreateBuilder(args); 5 | 6 | // Add services to the container. 7 | 8 | builder.Services.AddControllers(); 9 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 10 | builder.Services.AddEndpointsApiExplorer(); 11 | builder.Services.AddSwaggerGen(); 12 | 13 | builder.Services.AddDbContext( 14 | options => 15 | { 16 | options.UseSqlServer(builder.Configuration.GetConnectionString("NorthwindDB")); 17 | }); 18 | 19 | builder.Services.AddMvc(option => option.EnableEndpointRouting = false) 20 | .AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore); 21 | 22 | var app = builder.Build(); 23 | 24 | // Configure the HTTP request pipeline. 25 | if (app.Environment.IsDevelopment()) 26 | { 27 | app.UseSwagger(); 28 | app.UseSwaggerUI(); 29 | } 30 | 31 | app.UseHttpsRedirection(); 32 | 33 | app.UseAuthorization(); 34 | 35 | app.MapControllers(); 36 | 37 | app.Run(); 38 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:59038/", 8 | "sslPort": 44318 9 | } 10 | }, 11 | "profiles": { 12 | "Northwind.MSSQL": { 13 | "commandName": "Project", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | }, 19 | "applicationUrl": "https://localhost:7237;http://localhost:5237", 20 | "dotnetRunMessages": true 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.MSSQL 2 | { 3 | public class WeatherForecast 4 | { 5 | public DateTime Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 10 | 11 | public string? Summary { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "ConnectionStrings": { 10 | "NorthwindDB": "Data Source=DESKTOP-8BF81DU\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /MS SQL Server/Northwind.MSSQL/efpt.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "CodeGenerationMode": 2, 3 | "ContextClassName": "NorthwindContext", 4 | "ContextNamespace": "Data", 5 | "DefaultDacpacSchema": null, 6 | "FilterSchemas": false, 7 | "IncludeConnectionString": false, 8 | "ModelNamespace": "Models", 9 | "OutputContextPath": "Data", 10 | "OutputPath": "Models", 11 | "ProjectRootNamespace": "Northwind.MSSQL", 12 | "Schemas": null, 13 | "SelectedHandlebarsLanguage": 0, 14 | "SelectedToBeGenerated": 0, 15 | "Tables": [ 16 | { 17 | "Name": "[dbo].[Categories]", 18 | "ObjectType": 0 19 | }, 20 | { 21 | "Name": "[dbo].[Customers]", 22 | "ObjectType": 0 23 | }, 24 | { 25 | "Name": "[dbo].[Employees]", 26 | "ObjectType": 0 27 | }, 28 | { 29 | "Name": "[dbo].[Order Details]", 30 | "ObjectType": 0 31 | }, 32 | { 33 | "Name": "[dbo].[Orders]", 34 | "ObjectType": 0 35 | }, 36 | { 37 | "Name": "[dbo].[Products]", 38 | "ObjectType": 0 39 | }, 40 | { 41 | "Name": "[dbo].[Shippers]", 42 | "ObjectType": 0 43 | }, 44 | { 45 | "Name": "[dbo].[Suppliers]", 46 | "ObjectType": 0 47 | }, 48 | { 49 | "Name": "[dbo].[Alphabetical list of products]", 50 | "ObjectType": 3 51 | }, 52 | { 53 | "Name": "[dbo].[Category Sales for 1997]", 54 | "ObjectType": 3 55 | }, 56 | { 57 | "Name": "[dbo].[Current Product List]", 58 | "ObjectType": 3 59 | }, 60 | { 61 | "Name": "[dbo].[Customer and Suppliers by City]", 62 | "ObjectType": 3 63 | }, 64 | { 65 | "Name": "[dbo].[Invoices]", 66 | "ObjectType": 3 67 | }, 68 | { 69 | "Name": "[dbo].[Order Details Extended]", 70 | "ObjectType": 3 71 | }, 72 | { 73 | "Name": "[dbo].[Order Subtotals]", 74 | "ObjectType": 3 75 | }, 76 | { 77 | "Name": "[dbo].[Orders Qry]", 78 | "ObjectType": 3 79 | }, 80 | { 81 | "Name": "[dbo].[Product Sales for 1997]", 82 | "ObjectType": 3 83 | }, 84 | { 85 | "Name": "[dbo].[Products Above Average Price]", 86 | "ObjectType": 3 87 | }, 88 | { 89 | "Name": "[dbo].[Products by Category]", 90 | "ObjectType": 3 91 | }, 92 | { 93 | "Name": "[dbo].[Quarterly Orders]", 94 | "ObjectType": 3 95 | }, 96 | { 97 | "Name": "[dbo].[Sales by Category]", 98 | "ObjectType": 3 99 | }, 100 | { 101 | "Name": "[dbo].[Sales Totals by Amount]", 102 | "ObjectType": 3 103 | }, 104 | { 105 | "Name": "[dbo].[Summary of Sales by Quarter]", 106 | "ObjectType": 3 107 | }, 108 | { 109 | "Name": "[dbo].[Summary of Sales by Year]", 110 | "ObjectType": 3 111 | }, 112 | { 113 | "Name": "[dbo].[CustOrderHist]", 114 | "ObjectType": 1 115 | }, 116 | { 117 | "Name": "[dbo].[CustOrdersDetail]", 118 | "ObjectType": 1 119 | }, 120 | { 121 | "Name": "[dbo].[CustOrdersOrders]", 122 | "ObjectType": 1 123 | }, 124 | { 125 | "Name": "[dbo].[Employee Sales by Country]", 126 | "ObjectType": 1 127 | }, 128 | { 129 | "Name": "[dbo].[Sales by Year]", 130 | "ObjectType": 1 131 | }, 132 | { 133 | "Name": "[dbo].[SalesByCategory]", 134 | "ObjectType": 1 135 | }, 136 | { 137 | "Name": "[dbo].[Ten Most Expensive Products]", 138 | "ObjectType": 1 139 | } 140 | ], 141 | "UiHint": "DESKTOP-8BF81DU\\SQLEXPRESS.Northwind", 142 | "UseBoolPropertiesWithoutDefaultSql": false, 143 | "UseDatabaseNames": false, 144 | "UseDbContextSplitting": false, 145 | "UseFluentApiOnly": true, 146 | "UseHandleBars": false, 147 | "UseInflector": true, 148 | "UseLegacyPluralizer": false, 149 | "UseNoConstructor": false, 150 | "UseNoDefaultConstructor": false, 151 | "UseNoNavigations": false, 152 | "UseNoObjectFilter": false, 153 | "UseNodaTime": false, 154 | "UseNullableReferences": false, 155 | "UseSchemaFolders": false, 156 | "UseSpatial": false 157 | } -------------------------------------------------------------------------------- /MySQL/Database/Loading Related Data.sql: -------------------------------------------------------------------------------- 1 | select p.ProductName,s.* from products p 2 | inner join suppliers s on s.SupplierID = p.SupplierID 3 | where ProductName = 'Chai' -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Controllers/ProductsController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.EntityFrameworkCore; 8 | using Northwind.Data; 9 | using Northwind.Models; 10 | 11 | namespace Northwind.MySQL.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class ProductsController : ControllerBase 16 | { 17 | private readonly NorthwindContext _context; 18 | private readonly NorthwindContextProcedures _contextProcedures; 19 | 20 | public ProductsController(NorthwindContext context, 21 | NorthwindContextProcedures contextProcedures) 22 | { 23 | _context = context; 24 | _contextProcedures = contextProcedures; 25 | } 26 | 27 | // GET: api/Products 28 | [HttpGet] 29 | public async Task>> GetProducts() 30 | { 31 | return await _context.Products.ToListAsync(); 32 | } 33 | 34 | // GET: api/Products/5 35 | [HttpGet("{id}")] 36 | public async Task> GetProduct(int id) 37 | { 38 | var product = await _context.Products.FindAsync(id); 39 | 40 | if (product == null) 41 | { 42 | return NotFound(); 43 | } 44 | 45 | return product; 46 | } 47 | 48 | // PUT: api/Products/5 49 | // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 50 | [HttpPut("{id}")] 51 | public async Task PutProduct(int id, Product product) 52 | { 53 | if (id != product.ProductId) 54 | { 55 | return BadRequest(); 56 | } 57 | 58 | _context.Entry(product).State = EntityState.Modified; 59 | 60 | try 61 | { 62 | await _context.SaveChangesAsync(); 63 | } 64 | catch (DbUpdateConcurrencyException) 65 | { 66 | if (!ProductExists(id)) 67 | { 68 | return NotFound(); 69 | } 70 | else 71 | { 72 | throw; 73 | } 74 | } 75 | 76 | return NoContent(); 77 | } 78 | 79 | // POST: api/Products 80 | // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 81 | [HttpPost] 82 | public async Task> PostProduct(Product product) 83 | { 84 | _context.Products.Add(product); 85 | await _context.SaveChangesAsync(); 86 | 87 | return CreatedAtAction("GetProduct", new { id = product.ProductId }, product); 88 | } 89 | 90 | // DELETE: api/Products/5 91 | [HttpDelete("{id}")] 92 | public async Task DeleteProduct(int id) 93 | { 94 | var product = await _context.Products.FindAsync(id); 95 | if (product == null) 96 | { 97 | return NotFound(); 98 | } 99 | 100 | _context.Products.Remove(product); 101 | await _context.SaveChangesAsync(); 102 | 103 | return NoContent(); 104 | } 105 | 106 | private bool ProductExists(int id) 107 | { 108 | return _context.Products.Any(e => e.ProductId == id); 109 | } 110 | 111 | //loading related data 112 | [HttpGet("GetSupplierFromProductName")] 113 | public async Task GetSupplierFromProductName(string? productName) 114 | { 115 | return await _context.Products 116 | .Include(p => p.Supplier) 117 | .Where(p => p.ProductName == productName) 118 | .FirstOrDefaultAsync(); 119 | } 120 | 121 | //calling a view 122 | [HttpGet("GetAlphabeticalListOfProducts")] 123 | public async Task> GetAlphabeticalListOfProducts() 124 | { 125 | return await _context.AlphabeticalListOfProducts.ToListAsync(); 126 | } 127 | 128 | //calling stored procedure 129 | [HttpGet("GetCustOrderHistory")] 130 | public async Task> GetCustOrderHistory(string customerId) 131 | { 132 | return await _contextProcedures.CustOrderHistories 133 | .FromSqlRaw("call cust_order_history({0})", customerId) 134 | .ToListAsync(); 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace Northwind.MySQL.Controllers 4 | { 5 | [ApiController] 6 | [Route("[controller]")] 7 | public class WeatherForecastController : ControllerBase 8 | { 9 | private static readonly string[] Summaries = new[] 10 | { 11 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 12 | }; 13 | 14 | private readonly ILogger _logger; 15 | 16 | public WeatherForecastController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | [HttpGet(Name = "GetWeatherForecast")] 22 | public IEnumerable Get() 23 | { 24 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 25 | { 26 | Date = DateTime.Now.AddDays(index), 27 | TemperatureC = Random.Shared.Next(-20, 55), 28 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 29 | }) 30 | .ToArray(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Data/NorthwindContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Northwind.Models; 6 | 7 | namespace Northwind.Data 8 | { 9 | public partial class NorthwindContext : DbContext 10 | { 11 | public NorthwindContext() 12 | { 13 | } 14 | 15 | public NorthwindContext(DbContextOptions options) 16 | : base(options) 17 | { 18 | } 19 | 20 | public virtual DbSet AlphabeticalListOfProducts { get; set; } = null!; 21 | public virtual DbSet Categories { get; set; } = null!; 22 | public virtual DbSet Customers { get; set; } = null!; 23 | public virtual DbSet Employees { get; set; } = null!; 24 | public virtual DbSet Orders { get; set; } = null!; 25 | public virtual DbSet Orderdetails { get; set; } = null!; 26 | public virtual DbSet Products { get; set; } = null!; 27 | public virtual DbSet Shippers { get; set; } = null!; 28 | public virtual DbSet Suppliers { get; set; } = null!; 29 | 30 | protected override void OnModelCreating(ModelBuilder modelBuilder) 31 | { 32 | modelBuilder.UseCollation("utf8mb4_0900_ai_ci") 33 | .HasCharSet("utf8mb4"); 34 | 35 | modelBuilder.Entity(entity => 36 | { 37 | entity.HasNoKey(); 38 | 39 | entity.ToView("alphabetical_list_of_products"); 40 | 41 | entity.Property(e => e.CategoryId).HasColumnName("CategoryID"); 42 | 43 | entity.Property(e => e.CategoryName) 44 | .HasMaxLength(15) 45 | .UseCollation("utf8_general_ci") 46 | .HasCharSet("utf8"); 47 | 48 | entity.Property(e => e.Discontinued).HasDefaultValueSql("'0'"); 49 | 50 | entity.Property(e => e.ProductId).HasColumnName("ProductID"); 51 | 52 | entity.Property(e => e.ProductName) 53 | .HasMaxLength(40) 54 | .UseCollation("utf8_general_ci") 55 | .HasCharSet("utf8"); 56 | 57 | entity.Property(e => e.QuantityPerUnit) 58 | .HasMaxLength(20) 59 | .UseCollation("utf8_general_ci") 60 | .HasCharSet("utf8"); 61 | 62 | entity.Property(e => e.ReorderLevel).HasDefaultValueSql("'0'"); 63 | 64 | entity.Property(e => e.SupplierId).HasColumnName("SupplierID"); 65 | 66 | entity.Property(e => e.UnitPrice) 67 | .HasPrecision(19, 4) 68 | .HasDefaultValueSql("'0.0000'"); 69 | 70 | entity.Property(e => e.UnitsInStock).HasDefaultValueSql("'0'"); 71 | 72 | entity.Property(e => e.UnitsOnOrder).HasDefaultValueSql("'0'"); 73 | }); 74 | 75 | modelBuilder.Entity(entity => 76 | { 77 | entity.ToTable("categories"); 78 | 79 | entity.HasCharSet("utf8") 80 | .UseCollation("utf8_general_ci"); 81 | 82 | entity.HasIndex(e => e.CategoryName, "CategoryName") 83 | .IsUnique(); 84 | 85 | entity.Property(e => e.CategoryId).HasColumnName("CategoryID"); 86 | 87 | entity.Property(e => e.CategoryName).HasMaxLength(15); 88 | }); 89 | 90 | modelBuilder.Entity(entity => 91 | { 92 | entity.ToTable("customers"); 93 | 94 | entity.HasCharSet("utf8") 95 | .UseCollation("utf8_general_ci"); 96 | 97 | entity.HasIndex(e => e.City, "City"); 98 | 99 | entity.HasIndex(e => e.CompanyName, "CompanyName"); 100 | 101 | entity.HasIndex(e => e.PostalCode, "PostalCode"); 102 | 103 | entity.HasIndex(e => e.Region, "Region"); 104 | 105 | entity.Property(e => e.CustomerId) 106 | .HasMaxLength(5) 107 | .HasColumnName("CustomerID"); 108 | 109 | entity.Property(e => e.Address).HasMaxLength(60); 110 | 111 | entity.Property(e => e.City).HasMaxLength(15); 112 | 113 | entity.Property(e => e.CompanyName).HasMaxLength(40); 114 | 115 | entity.Property(e => e.ContactName).HasMaxLength(30); 116 | 117 | entity.Property(e => e.ContactTitle).HasMaxLength(30); 118 | 119 | entity.Property(e => e.Country).HasMaxLength(15); 120 | 121 | entity.Property(e => e.Fax).HasMaxLength(24); 122 | 123 | entity.Property(e => e.Phone).HasMaxLength(24); 124 | 125 | entity.Property(e => e.PostalCode).HasMaxLength(10); 126 | 127 | entity.Property(e => e.Region).HasMaxLength(15); 128 | }); 129 | 130 | modelBuilder.Entity(entity => 131 | { 132 | entity.ToTable("employees"); 133 | 134 | entity.HasCharSet("utf8") 135 | .UseCollation("utf8_general_ci"); 136 | 137 | entity.HasIndex(e => e.LastName, "LastName"); 138 | 139 | entity.HasIndex(e => e.PostalCode, "PostalCode"); 140 | 141 | entity.Property(e => e.EmployeeId).HasColumnName("EmployeeID"); 142 | 143 | entity.Property(e => e.Address).HasMaxLength(60); 144 | 145 | entity.Property(e => e.BirthDate).HasColumnType("datetime"); 146 | 147 | entity.Property(e => e.City).HasMaxLength(15); 148 | 149 | entity.Property(e => e.Country).HasMaxLength(15); 150 | 151 | entity.Property(e => e.Extension).HasMaxLength(4); 152 | 153 | entity.Property(e => e.FirstName).HasMaxLength(10); 154 | 155 | entity.Property(e => e.HireDate).HasColumnType("datetime"); 156 | 157 | entity.Property(e => e.HomePhone).HasMaxLength(24); 158 | 159 | entity.Property(e => e.LastName).HasMaxLength(20); 160 | 161 | entity.Property(e => e.PostalCode).HasMaxLength(10); 162 | 163 | entity.Property(e => e.Region).HasMaxLength(15); 164 | 165 | entity.Property(e => e.Title).HasMaxLength(30); 166 | 167 | entity.Property(e => e.TitleOfCourtesy).HasMaxLength(25); 168 | }); 169 | 170 | modelBuilder.Entity(entity => 171 | { 172 | entity.ToTable("orders"); 173 | 174 | entity.HasCharSet("utf8") 175 | .UseCollation("utf8_general_ci"); 176 | 177 | entity.HasIndex(e => e.CustomerId, "FK_CustomersOrders"); 178 | 179 | entity.HasIndex(e => e.EmployeeId, "FK_EmployeesOrders"); 180 | 181 | entity.HasIndex(e => e.OrderDate, "OrderDate"); 182 | 183 | entity.HasIndex(e => e.ShipPostalCode, "ShipPostalCode"); 184 | 185 | entity.HasIndex(e => e.ShippedDate, "ShippedDate"); 186 | 187 | entity.Property(e => e.OrderId).HasColumnName("OrderID"); 188 | 189 | entity.Property(e => e.CustomerId) 190 | .HasMaxLength(5) 191 | .HasColumnName("CustomerID"); 192 | 193 | entity.Property(e => e.EmployeeId).HasColumnName("EmployeeID"); 194 | 195 | entity.Property(e => e.Freight) 196 | .HasPrecision(19, 4) 197 | .HasDefaultValueSql("'0.0000'"); 198 | 199 | entity.Property(e => e.OrderDate).HasColumnType("datetime"); 200 | 201 | entity.Property(e => e.RequiredDate).HasColumnType("datetime"); 202 | 203 | entity.Property(e => e.ShipAddress).HasMaxLength(60); 204 | 205 | entity.Property(e => e.ShipCity).HasMaxLength(15); 206 | 207 | entity.Property(e => e.ShipCountry).HasMaxLength(15); 208 | 209 | entity.Property(e => e.ShipName).HasMaxLength(40); 210 | 211 | entity.Property(e => e.ShipPostalCode).HasMaxLength(10); 212 | 213 | entity.Property(e => e.ShipRegion).HasMaxLength(15); 214 | 215 | entity.Property(e => e.ShippedDate).HasColumnType("datetime"); 216 | 217 | entity.HasOne(d => d.Customer) 218 | .WithMany(p => p.Orders) 219 | .HasForeignKey(d => d.CustomerId) 220 | .HasConstraintName("FK_CustomersOrders"); 221 | 222 | entity.HasOne(d => d.Employee) 223 | .WithMany(p => p.Orders) 224 | .HasForeignKey(d => d.EmployeeId) 225 | .HasConstraintName("FK_EmployeesOrders"); 226 | }); 227 | 228 | modelBuilder.Entity(entity => 229 | { 230 | entity.HasKey(e => e.OrderDetailsId) 231 | .HasName("PRIMARY"); 232 | 233 | entity.ToTable("orderdetails"); 234 | 235 | entity.HasCharSet("utf8") 236 | .UseCollation("utf8_general_ci"); 237 | 238 | entity.HasIndex(e => e.OrderId, "FK_OrdersOrderDetails"); 239 | 240 | entity.HasIndex(e => e.ProductId, "FK_ProductsOrderDetails"); 241 | 242 | entity.Property(e => e.OrderDetailsId).HasColumnName("OrderDetailsID"); 243 | 244 | entity.Property(e => e.OrderId).HasColumnName("OrderID"); 245 | 246 | entity.Property(e => e.ProductId).HasColumnName("ProductID"); 247 | 248 | entity.Property(e => e.Quantity).HasDefaultValueSql("'1'"); 249 | 250 | entity.Property(e => e.UnitPrice).HasPrecision(19, 4); 251 | 252 | entity.HasOne(d => d.Order) 253 | .WithMany(p => p.Orderdetails) 254 | .HasForeignKey(d => d.OrderId) 255 | .OnDelete(DeleteBehavior.ClientSetNull) 256 | .HasConstraintName("FK_OrdersOrderDetails"); 257 | 258 | entity.HasOne(d => d.Product) 259 | .WithMany(p => p.Orderdetails) 260 | .HasForeignKey(d => d.ProductId) 261 | .OnDelete(DeleteBehavior.ClientSetNull) 262 | .HasConstraintName("FK_ProductsOrderDetails"); 263 | }); 264 | 265 | modelBuilder.Entity(entity => 266 | { 267 | entity.ToTable("products"); 268 | 269 | entity.HasCharSet("utf8") 270 | .UseCollation("utf8_general_ci"); 271 | 272 | entity.HasIndex(e => e.CategoryId, "FK_ProductsCategories"); 273 | 274 | entity.HasIndex(e => e.SupplierId, "FK_ProductsSuppliers"); 275 | 276 | entity.Property(e => e.ProductId).HasColumnName("ProductID"); 277 | 278 | entity.Property(e => e.CategoryId).HasColumnName("CategoryID"); 279 | 280 | entity.Property(e => e.Discontinued).HasDefaultValueSql("'0'"); 281 | 282 | entity.Property(e => e.ProductName).HasMaxLength(40); 283 | 284 | entity.Property(e => e.QuantityPerUnit).HasMaxLength(20); 285 | 286 | entity.Property(e => e.ReorderLevel).HasDefaultValueSql("'0'"); 287 | 288 | entity.Property(e => e.SupplierId).HasColumnName("SupplierID"); 289 | 290 | entity.Property(e => e.UnitPrice) 291 | .HasPrecision(19, 4) 292 | .HasDefaultValueSql("'0.0000'"); 293 | 294 | entity.Property(e => e.UnitsInStock).HasDefaultValueSql("'0'"); 295 | 296 | entity.Property(e => e.UnitsOnOrder).HasDefaultValueSql("'0'"); 297 | 298 | entity.HasOne(d => d.Category) 299 | .WithMany(p => p.Products) 300 | .HasForeignKey(d => d.CategoryId) 301 | .HasConstraintName("FK_ProductsCategories"); 302 | 303 | entity.HasOne(d => d.Supplier) 304 | .WithMany(p => p.Products) 305 | .HasForeignKey(d => d.SupplierId) 306 | .HasConstraintName("FK_ProductsSuppliers"); 307 | }); 308 | 309 | modelBuilder.Entity(entity => 310 | { 311 | entity.ToTable("shippers"); 312 | 313 | entity.HasCharSet("utf8") 314 | .UseCollation("utf8_general_ci"); 315 | 316 | entity.Property(e => e.ShipperId).HasColumnName("ShipperID"); 317 | 318 | entity.Property(e => e.CompanyName).HasMaxLength(40); 319 | 320 | entity.Property(e => e.Phone).HasMaxLength(24); 321 | }); 322 | 323 | modelBuilder.Entity(entity => 324 | { 325 | entity.ToTable("suppliers"); 326 | 327 | entity.HasCharSet("utf8") 328 | .UseCollation("utf8_general_ci"); 329 | 330 | entity.HasIndex(e => e.CompanyName, "CompanyName"); 331 | 332 | entity.HasIndex(e => e.PostalCode, "PostalCode"); 333 | 334 | entity.Property(e => e.SupplierId).HasColumnName("SupplierID"); 335 | 336 | entity.Property(e => e.Address).HasMaxLength(60); 337 | 338 | entity.Property(e => e.City).HasMaxLength(15); 339 | 340 | entity.Property(e => e.CompanyName).HasMaxLength(40); 341 | 342 | entity.Property(e => e.ContactName).HasMaxLength(30); 343 | 344 | entity.Property(e => e.ContactTitle).HasMaxLength(30); 345 | 346 | entity.Property(e => e.Country).HasMaxLength(15); 347 | 348 | entity.Property(e => e.Fax).HasMaxLength(24); 349 | 350 | entity.Property(e => e.Phone).HasMaxLength(24); 351 | 352 | entity.Property(e => e.PostalCode).HasMaxLength(10); 353 | 354 | entity.Property(e => e.Region).HasMaxLength(15); 355 | }); 356 | 357 | OnModelCreatingPartial(modelBuilder); 358 | } 359 | 360 | partial void OnModelCreatingPartial(ModelBuilder modelBuilder); 361 | } 362 | } 363 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Models/AlphabeticalListOfProduct.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class AlphabeticalListOfProduct 7 | { 8 | public int ProductId { get; set; } 9 | public string ProductName { get; set; } = null!; 10 | public int? SupplierId { get; set; } 11 | public int? CategoryId { get; set; } 12 | public string? QuantityPerUnit { get; set; } 13 | public decimal? UnitPrice { get; set; } 14 | public int? UnitsInStock { get; set; } 15 | public int? UnitsOnOrder { get; set; } 16 | public int? ReorderLevel { get; set; } 17 | public bool? Discontinued { get; set; } 18 | public string CategoryName { get; set; } = null!; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Models/Category.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Category 7 | { 8 | public Category() 9 | { 10 | Products = new HashSet(); 11 | } 12 | 13 | public int CategoryId { get; set; } 14 | public string CategoryName { get; set; } = null!; 15 | public string? Description { get; set; } 16 | 17 | public virtual ICollection Products { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Models/Customer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Customer 7 | { 8 | public Customer() 9 | { 10 | Orders = new HashSet(); 11 | } 12 | 13 | public string CustomerId { get; set; } = null!; 14 | public string CompanyName { get; set; } = null!; 15 | public string? ContactName { get; set; } 16 | public string? ContactTitle { get; set; } 17 | public string? Address { get; set; } 18 | public string? City { get; set; } 19 | public string? Region { get; set; } 20 | public string? PostalCode { get; set; } 21 | public string? Country { get; set; } 22 | public string? Phone { get; set; } 23 | public string? Fax { get; set; } 24 | 25 | public virtual ICollection Orders { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Models/Employee.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Employee 7 | { 8 | public Employee() 9 | { 10 | Orders = new HashSet(); 11 | } 12 | 13 | public int EmployeeId { get; set; } 14 | public string LastName { get; set; } = null!; 15 | public string FirstName { get; set; } = null!; 16 | public string? Title { get; set; } 17 | public string? TitleOfCourtesy { get; set; } 18 | public DateTime? BirthDate { get; set; } 19 | public DateTime? HireDate { get; set; } 20 | public string? Address { get; set; } 21 | public string? City { get; set; } 22 | public string? Region { get; set; } 23 | public string? PostalCode { get; set; } 24 | public string? Country { get; set; } 25 | public string? HomePhone { get; set; } 26 | public string? Extension { get; set; } 27 | public string? Notes { get; set; } 28 | public int? ReportsTo { get; set; } 29 | 30 | public virtual ICollection Orders { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Models/Order.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Order 7 | { 8 | public Order() 9 | { 10 | Orderdetails = new HashSet(); 11 | } 12 | 13 | public int OrderId { get; set; } 14 | public string? CustomerId { get; set; } 15 | public int? EmployeeId { get; set; } 16 | public DateTime? OrderDate { get; set; } 17 | public DateTime? RequiredDate { get; set; } 18 | public DateTime? ShippedDate { get; set; } 19 | public int? ShipVia { get; set; } 20 | public decimal? Freight { get; set; } 21 | public string? ShipName { get; set; } 22 | public string? ShipAddress { get; set; } 23 | public string? ShipCity { get; set; } 24 | public string? ShipRegion { get; set; } 25 | public string? ShipPostalCode { get; set; } 26 | public string? ShipCountry { get; set; } 27 | 28 | public virtual Customer? Customer { get; set; } 29 | public virtual Employee? Employee { get; set; } 30 | public virtual ICollection Orderdetails { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Models/Orderdetail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Orderdetail 7 | { 8 | public int OrderDetailsId { get; set; } 9 | public int OrderId { get; set; } 10 | public int ProductId { get; set; } 11 | public decimal UnitPrice { get; set; } 12 | public int Quantity { get; set; } 13 | public float Discount { get; set; } 14 | 15 | public virtual Order Order { get; set; } = null!; 16 | public virtual Product Product { get; set; } = null!; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Models/Product.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Product 7 | { 8 | public Product() 9 | { 10 | Orderdetails = new HashSet(); 11 | } 12 | 13 | public int ProductId { get; set; } 14 | public string ProductName { get; set; } = null!; 15 | public int? SupplierId { get; set; } 16 | public int? CategoryId { get; set; } 17 | public string? QuantityPerUnit { get; set; } 18 | public decimal? UnitPrice { get; set; } 19 | public int? UnitsInStock { get; set; } 20 | public int? UnitsOnOrder { get; set; } 21 | public int? ReorderLevel { get; set; } 22 | public bool? Discontinued { get; set; } 23 | 24 | public virtual Category? Category { get; set; } 25 | public virtual Supplier? Supplier { get; set; } 26 | public virtual ICollection Orderdetails { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Models/Shipper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Shipper 7 | { 8 | public int ShipperId { get; set; } 9 | public string CompanyName { get; set; } = null!; 10 | public string? Phone { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Models/Supplier.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Supplier 7 | { 8 | public Supplier() 9 | { 10 | Products = new HashSet(); 11 | } 12 | 13 | public int SupplierId { get; set; } 14 | public string CompanyName { get; set; } = null!; 15 | public string? ContactName { get; set; } 16 | public string? ContactTitle { get; set; } 17 | public string? Address { get; set; } 18 | public string? City { get; set; } 19 | public string? Region { get; set; } 20 | public string? PostalCode { get; set; } 21 | public string? Country { get; set; } 22 | public string? Phone { get; set; } 23 | public string? Fax { get; set; } 24 | public string? HomePage { get; set; } 25 | 26 | public virtual ICollection Products { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Northwind.MySQL.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | runtime; build; native; contentfiles; analyzers; buildtransitive 13 | all 14 | 15 | 16 | 17 | all 18 | runtime; build; native; contentfiles; analyzers; buildtransitive 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Northwind.MySQL.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31912.275 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Northwind.MySQL", "Northwind.MySQL.csproj", "{31AC8205-1DB1-4A31-977D-73BB4FE29D1D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {31AC8205-1DB1-4A31-977D-73BB4FE29D1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {31AC8205-1DB1-4A31-977D-73BB4FE29D1D}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {31AC8205-1DB1-4A31-977D-73BB4FE29D1D}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {31AC8205-1DB1-4A31-977D-73BB4FE29D1D}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {4D884DCB-F241-4E2A-AF00-B74FD3B81FA5} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Procedures/CustOrderHistory.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Data 2 | { 3 | public class CustOrderHistory 4 | { 5 | public string? ProductName { get; set; } 6 | public int Total { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Procedures/NorthwindContextProcedures.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace Northwind.Data 4 | { 5 | public partial class NorthwindContextProcedures : DbContext 6 | { 7 | public virtual DbSet CustOrderHistories { get; set; } = null!; 8 | 9 | public NorthwindContextProcedures(){} 10 | 11 | public NorthwindContextProcedures(DbContextOptions options) 12 | : base(options) { } 13 | 14 | protected override void OnModelCreating(ModelBuilder modelBuilder) 15 | { 16 | modelBuilder.Entity(entity => 17 | { 18 | entity.HasNoKey(); 19 | entity.Property(e => e.ProductName); 20 | entity.Property(e => e.Total); 21 | }); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Newtonsoft.Json; 3 | using Northwind.Data; 4 | 5 | var builder = WebApplication.CreateBuilder(args); 6 | 7 | // Add services to the container. 8 | 9 | builder.Services.AddControllers(); 10 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 11 | builder.Services.AddEndpointsApiExplorer(); 12 | builder.Services.AddSwaggerGen(); 13 | 14 | builder.Services.AddDbContext( 15 | options => 16 | { 17 | options.UseMySql(builder.Configuration.GetConnectionString("NorthwindDB"), 18 | Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.0.23-mysql")); 19 | }); 20 | 21 | builder.Services.AddMvc(option => option.EnableEndpointRouting = false) 22 | .AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore); 23 | 24 | builder.Services.AddDbContext( 25 | options => 26 | { 27 | options.UseMySql(builder.Configuration.GetConnectionString("NorthwindDB"), 28 | Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.0.23-mysql")); 29 | }); 30 | 31 | var app = builder.Build(); 32 | 33 | // Configure the HTTP request pipeline. 34 | if (app.Environment.IsDevelopment()) 35 | { 36 | app.UseSwagger(); 37 | app.UseSwaggerUI(); 38 | } 39 | 40 | app.UseHttpsRedirection(); 41 | 42 | app.UseAuthorization(); 43 | 44 | app.MapControllers(); 45 | 46 | app.Run(); 47 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:47675", 8 | "sslPort": 44371 9 | } 10 | }, 11 | "profiles": { 12 | "Northwind.MySQL": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:7216;http://localhost:5216", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.MySQL 2 | { 3 | public class WeatherForecast 4 | { 5 | public DateTime Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 10 | 11 | public string? Summary { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MySQL/Northwind.MySQL/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "ConnectionStrings": { 10 | "NorthwindDB": "Server=localhost;Database=Northwind;Uid=root;Pwd=root" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /MySQL/Steps.txt: -------------------------------------------------------------------------------- 1 | Add Connection String => 2 | Server=localhost;Database=Northwind;Uid=root;Pwd=root 3 | 4 | Packages to install => 5 | dotnet add package Microsoft.EntityFrameworkCore.Design 6 | dotnet add package Pomelo.EntityFrameworkCore.MySql 7 | 8 | Install & Update dotnet EF tool => 9 | dotnet tool install --global dotnet-ef 10 | dotnet tool update --global dotnet-ef 11 | 12 | Scaffold MySQL Database => 13 | dotnet ef dbcontext scaffold Name=NorthwindDB Pomelo.EntityFrameworkCore.MySql --output-dir Models --context-dir Data --namespace Northwind.Models --context-namespace Northwind.Data --context NorthwindContext -f --no-onconfiguring 14 | 15 | dotnet add package Microsoft.AspNetCore.Mvc.NewtonsoftJson -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This repository contains sample .NET projects which are using EF Core to perform database operations for MS SQL Server, MySQL, SQLite & CosmosDB. We have created these projects for developers who are getting started with EF Core and they want to know how you perform CRUD operations, load related data, load data from views and call stored procedures. 3 | 4 | # Tutorials 5 | We have created tutorials for you to create these projects from scratch. Please check the list below to create Web APIs for your databases. 6 | 7 | | Database | Tutorial | 8 | | ----- | ---- | 9 | | MS SQL Server | https://youtu.be/DoYmpAPoixI | 10 | | MySQL | https://youtu.be/pzFY45La2LE | 11 | | SQLite | https://youtu.be/xs3JKpePnvs | 12 | | CosmosDB | https://youtu.be/j5ylkjbJmu4 | 13 | 14 | # Contact Us 15 | 16 | If you have any questions on how this project is setup then you can reach out to us on below handles. 17 | 18 | https://twitter.com/curious_drive
19 | https://www.facebook.com/curiousdrive/
20 | https://www.youtube.com/c/curiousdrive
21 | 22 | Let us know how it goes. 23 | -------------------------------------------------------------------------------- /SQLite/Database/Load Related Data.sql: -------------------------------------------------------------------------------- 1 | SELECT p.ProductName, od.* from Product p 2 | inner join OrderDetail od ON od.ProductId = p.Id 3 | where p.Id = 14 4 | 5 | 6 | -------------------------------------------------------------------------------- /SQLite/Database/northwind.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CuriousDrive/EFCore.AllDatabasesConsidered/467f5253fb2d02a043f76a8033fc56e984ff60c0/SQLite/Database/northwind.sqlite -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Controllers/ProductsController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.EntityFrameworkCore; 8 | using Northwind.Data; 9 | using Northwind.Models; 10 | 11 | namespace Northwind.SQLite.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class ProductsController : ControllerBase 16 | { 17 | private readonly NorthwindContext _context; 18 | 19 | public ProductsController(NorthwindContext context) 20 | { 21 | _context = context; 22 | } 23 | 24 | // GET: api/Products 25 | [HttpGet] 26 | public async Task>> GetProducts() 27 | { 28 | return await _context.Products.ToListAsync(); 29 | } 30 | 31 | // GET: api/Products/5 32 | [HttpGet("{id}")] 33 | public async Task> GetProduct(long id) 34 | { 35 | var product = await _context.Products.FindAsync(id); 36 | 37 | if (product == null) 38 | { 39 | return NotFound(); 40 | } 41 | 42 | return product; 43 | } 44 | 45 | // PUT: api/Products/5 46 | // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 47 | [HttpPut("{id}")] 48 | public async Task PutProduct(long id, Product product) 49 | { 50 | if (id != product.Id) 51 | { 52 | return BadRequest(); 53 | } 54 | 55 | _context.Entry(product).State = EntityState.Modified; 56 | 57 | try 58 | { 59 | await _context.SaveChangesAsync(); 60 | } 61 | catch (DbUpdateConcurrencyException) 62 | { 63 | if (!ProductExists(id)) 64 | { 65 | return NotFound(); 66 | } 67 | else 68 | { 69 | throw; 70 | } 71 | } 72 | 73 | return NoContent(); 74 | } 75 | 76 | // POST: api/Products 77 | // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 78 | [HttpPost] 79 | public async Task> PostProduct(Product product) 80 | { 81 | _context.Products.Add(product); 82 | try 83 | { 84 | await _context.SaveChangesAsync(); 85 | } 86 | catch (DbUpdateException) 87 | { 88 | if (ProductExists(product.Id)) 89 | { 90 | return Conflict(); 91 | } 92 | else 93 | { 94 | throw; 95 | } 96 | } 97 | 98 | return CreatedAtAction("GetProduct", new { id = product.Id }, product); 99 | } 100 | 101 | // DELETE: api/Products/5 102 | [HttpDelete("{id}")] 103 | public async Task DeleteProduct(long id) 104 | { 105 | var product = await _context.Products.FindAsync(id); 106 | if (product == null) 107 | { 108 | return NotFound(); 109 | } 110 | 111 | _context.Products.Remove(product); 112 | await _context.SaveChangesAsync(); 113 | 114 | return NoContent(); 115 | } 116 | 117 | private bool ProductExists(long id) 118 | { 119 | return _context.Products.Any(e => e.Id == id); 120 | } 121 | 122 | [HttpGet("GetProductDetails")] 123 | public async Task> GetProductDetails() 124 | { 125 | return await _context.ProductDetails.ToListAsync(); 126 | } 127 | 128 | [HttpGet("GetProductOrderDetails")] 129 | public async Task> GetProductOrderDetails(long productId) 130 | { 131 | return await _context.Products 132 | .Include(e => e.OrderDetails) 133 | .Where(p => p.Id == productId) 134 | .ToListAsync(); 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace Northwind.SQLite.Controllers 4 | { 5 | [ApiController] 6 | [Route("[controller]")] 7 | public class WeatherForecastController : ControllerBase 8 | { 9 | private static readonly string[] Summaries = new[] 10 | { 11 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 12 | }; 13 | 14 | private readonly ILogger _logger; 15 | 16 | public WeatherForecastController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | [HttpGet(Name = "GetWeatherForecast")] 22 | public IEnumerable Get() 23 | { 24 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 25 | { 26 | Date = DateTime.Now.AddDays(index), 27 | TemperatureC = Random.Shared.Next(-20, 55), 28 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 29 | }) 30 | .ToArray(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Data/NorthwindContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Northwind.Models; 6 | 7 | namespace Northwind.Data 8 | { 9 | public partial class NorthwindContext : DbContext 10 | { 11 | public NorthwindContext() 12 | { 13 | } 14 | 15 | public NorthwindContext(DbContextOptions options) 16 | : base(options) 17 | { 18 | } 19 | 20 | public virtual DbSet Categories { get; set; } = null!; 21 | public virtual DbSet Customers { get; set; } = null!; 22 | public virtual DbSet Employees { get; set; } = null!; 23 | public virtual DbSet EmployeeTerritories { get; set; } = null!; 24 | public virtual DbSet Orders { get; set; } = null!; 25 | public virtual DbSet OrderDetails { get; set; } = null!; 26 | public virtual DbSet Products { get; set; } = null!; 27 | public virtual DbSet ProductDetails { get; set; } = null!; 28 | public virtual DbSet Regions { get; set; } = null!; 29 | public virtual DbSet Shippers { get; set; } = null!; 30 | public virtual DbSet Suppliers { get; set; } = null!; 31 | public virtual DbSet Territories { get; set; } = null!; 32 | 33 | protected override void OnModelCreating(ModelBuilder modelBuilder) 34 | { 35 | modelBuilder.Entity(entity => 36 | { 37 | entity.ToTable("Category"); 38 | 39 | entity.Property(e => e.Id).ValueGeneratedNever(); 40 | 41 | entity.Property(e => e.CategoryName).HasColumnType("VARCHAR(8000)"); 42 | 43 | entity.Property(e => e.Description).HasColumnType("VARCHAR(8000)"); 44 | }); 45 | 46 | modelBuilder.Entity(entity => 47 | { 48 | entity.ToTable("Customer"); 49 | 50 | entity.Property(e => e.Id).HasColumnType("VARCHAR(8000)"); 51 | 52 | entity.Property(e => e.Address).HasColumnType("VARCHAR(8000)"); 53 | 54 | entity.Property(e => e.City).HasColumnType("VARCHAR(8000)"); 55 | 56 | entity.Property(e => e.CompanyName).HasColumnType("VARCHAR(8000)"); 57 | 58 | entity.Property(e => e.ContactName).HasColumnType("VARCHAR(8000)"); 59 | 60 | entity.Property(e => e.ContactTitle).HasColumnType("VARCHAR(8000)"); 61 | 62 | entity.Property(e => e.Country).HasColumnType("VARCHAR(8000)"); 63 | 64 | entity.Property(e => e.Fax).HasColumnType("VARCHAR(8000)"); 65 | 66 | entity.Property(e => e.Phone).HasColumnType("VARCHAR(8000)"); 67 | 68 | entity.Property(e => e.PostalCode).HasColumnType("VARCHAR(8000)"); 69 | 70 | entity.Property(e => e.Region).HasColumnType("VARCHAR(8000)"); 71 | }); 72 | 73 | modelBuilder.Entity(entity => 74 | { 75 | entity.ToTable("Employee"); 76 | 77 | entity.Property(e => e.Id).ValueGeneratedNever(); 78 | 79 | entity.Property(e => e.Address).HasColumnType("VARCHAR(8000)"); 80 | 81 | entity.Property(e => e.BirthDate).HasColumnType("VARCHAR(8000)"); 82 | 83 | entity.Property(e => e.City).HasColumnType("VARCHAR(8000)"); 84 | 85 | entity.Property(e => e.Country).HasColumnType("VARCHAR(8000)"); 86 | 87 | entity.Property(e => e.Extension).HasColumnType("VARCHAR(8000)"); 88 | 89 | entity.Property(e => e.FirstName).HasColumnType("VARCHAR(8000)"); 90 | 91 | entity.Property(e => e.HireDate).HasColumnType("VARCHAR(8000)"); 92 | 93 | entity.Property(e => e.HomePhone).HasColumnType("VARCHAR(8000)"); 94 | 95 | entity.Property(e => e.LastName).HasColumnType("VARCHAR(8000)"); 96 | 97 | entity.Property(e => e.Notes).HasColumnType("VARCHAR(8000)"); 98 | 99 | entity.Property(e => e.PhotoPath).HasColumnType("VARCHAR(8000)"); 100 | 101 | entity.Property(e => e.PostalCode).HasColumnType("VARCHAR(8000)"); 102 | 103 | entity.Property(e => e.Region).HasColumnType("VARCHAR(8000)"); 104 | 105 | entity.Property(e => e.Title).HasColumnType("VARCHAR(8000)"); 106 | 107 | entity.Property(e => e.TitleOfCourtesy).HasColumnType("VARCHAR(8000)"); 108 | }); 109 | 110 | modelBuilder.Entity(entity => 111 | { 112 | entity.ToTable("EmployeeTerritory"); 113 | 114 | entity.Property(e => e.Id).HasColumnType("VARCHAR(8000)"); 115 | 116 | entity.Property(e => e.TerritoryId).HasColumnType("VARCHAR(8000)"); 117 | 118 | entity.HasOne(d => d.Employee) 119 | .WithMany(p => p.EmployeeTerritories) 120 | .HasForeignKey(d => d.EmployeeId); 121 | 122 | entity.HasOne(d => d.Territory) 123 | .WithMany(p => p.EmployeeTerritories) 124 | .HasForeignKey(d => d.TerritoryId); 125 | }); 126 | 127 | modelBuilder.Entity(entity => 128 | { 129 | entity.ToTable("Order"); 130 | 131 | entity.Property(e => e.Id).ValueGeneratedNever(); 132 | 133 | entity.Property(e => e.CustomerId).HasColumnType("VARCHAR(8000)"); 134 | 135 | entity.Property(e => e.Freight).HasColumnType("DECIMAL"); 136 | 137 | entity.Property(e => e.OrderDate).HasColumnType("VARCHAR(8000)"); 138 | 139 | entity.Property(e => e.RequiredDate).HasColumnType("VARCHAR(8000)"); 140 | 141 | entity.Property(e => e.ShipAddress).HasColumnType("VARCHAR(8000)"); 142 | 143 | entity.Property(e => e.ShipCity).HasColumnType("VARCHAR(8000)"); 144 | 145 | entity.Property(e => e.ShipCountry).HasColumnType("VARCHAR(8000)"); 146 | 147 | entity.Property(e => e.ShipName).HasColumnType("VARCHAR(8000)"); 148 | 149 | entity.Property(e => e.ShipPostalCode).HasColumnType("VARCHAR(8000)"); 150 | 151 | entity.Property(e => e.ShipRegion).HasColumnType("VARCHAR(8000)"); 152 | 153 | entity.Property(e => e.ShippedDate).HasColumnType("VARCHAR(8000)"); 154 | 155 | entity.HasOne(d => d.Customer) 156 | .WithMany(p => p.Orders) 157 | .HasForeignKey(d => d.CustomerId); 158 | 159 | entity.HasOne(d => d.Employee) 160 | .WithMany(p => p.Orders) 161 | .HasForeignKey(d => d.EmployeeId) 162 | .OnDelete(DeleteBehavior.ClientSetNull); 163 | }); 164 | 165 | modelBuilder.Entity(entity => 166 | { 167 | entity.ToTable("OrderDetail"); 168 | 169 | entity.Property(e => e.Id).HasColumnType("VARCHAR(8000)"); 170 | 171 | entity.Property(e => e.Discount).HasColumnType("DOUBLE"); 172 | 173 | entity.Property(e => e.UnitPrice).HasColumnType("DECIMAL"); 174 | 175 | entity.HasOne(d => d.Order) 176 | .WithMany(p => p.OrderDetails) 177 | .HasForeignKey(d => d.OrderId); 178 | 179 | entity.HasOne(d => d.Product) 180 | .WithMany(p => p.OrderDetails) 181 | .HasForeignKey(d => d.ProductId); 182 | }); 183 | 184 | modelBuilder.Entity(entity => 185 | { 186 | entity.ToTable("Product"); 187 | 188 | entity.Property(e => e.Id).ValueGeneratedNever(); 189 | 190 | entity.Property(e => e.ProductName).HasColumnType("VARCHAR(8000)"); 191 | 192 | entity.Property(e => e.QuantityPerUnit).HasColumnType("VARCHAR(8000)"); 193 | 194 | entity.Property(e => e.UnitPrice).HasColumnType("DECIMAL"); 195 | 196 | entity.HasOne(d => d.Category) 197 | .WithMany(p => p.Products) 198 | .HasForeignKey(d => d.CategoryId); 199 | 200 | entity.HasOne(d => d.Supplier) 201 | .WithMany(p => p.Products) 202 | .HasForeignKey(d => d.SupplierId); 203 | }); 204 | 205 | modelBuilder.Entity(entity => 206 | { 207 | entity.HasNoKey(); 208 | 209 | entity.ToView("ProductDetails"); 210 | 211 | entity.Property(e => e.CategoryDescription).HasColumnType("VARCHAR(8000)"); 212 | 213 | entity.Property(e => e.CategoryName).HasColumnType("VARCHAR(8000)"); 214 | 215 | entity.Property(e => e.ProductName).HasColumnType("VARCHAR(8000)"); 216 | 217 | entity.Property(e => e.QuantityPerUnit).HasColumnType("VARCHAR(8000)"); 218 | 219 | entity.Property(e => e.SupplierName).HasColumnType("VARCHAR(8000)"); 220 | 221 | entity.Property(e => e.SupplierRegion).HasColumnType("VARCHAR(8000)"); 222 | 223 | entity.Property(e => e.UnitPrice).HasColumnType("DECIMAL"); 224 | }); 225 | 226 | modelBuilder.Entity(entity => 227 | { 228 | entity.ToTable("Region"); 229 | 230 | entity.Property(e => e.Id).ValueGeneratedNever(); 231 | 232 | entity.Property(e => e.RegionDescription).HasColumnType("VARCHAR(8000)"); 233 | }); 234 | 235 | modelBuilder.Entity(entity => 236 | { 237 | entity.ToTable("Shipper"); 238 | 239 | entity.Property(e => e.Id).ValueGeneratedNever(); 240 | 241 | entity.Property(e => e.CompanyName).HasColumnType("VARCHAR(8000)"); 242 | 243 | entity.Property(e => e.Phone).HasColumnType("VARCHAR(8000)"); 244 | }); 245 | 246 | modelBuilder.Entity(entity => 247 | { 248 | entity.ToTable("Supplier"); 249 | 250 | entity.Property(e => e.Id).ValueGeneratedNever(); 251 | 252 | entity.Property(e => e.Address).HasColumnType("VARCHAR(8000)"); 253 | 254 | entity.Property(e => e.City).HasColumnType("VARCHAR(8000)"); 255 | 256 | entity.Property(e => e.CompanyName).HasColumnType("VARCHAR(8000)"); 257 | 258 | entity.Property(e => e.ContactName).HasColumnType("VARCHAR(8000)"); 259 | 260 | entity.Property(e => e.ContactTitle).HasColumnType("VARCHAR(8000)"); 261 | 262 | entity.Property(e => e.Country).HasColumnType("VARCHAR(8000)"); 263 | 264 | entity.Property(e => e.Fax).HasColumnType("VARCHAR(8000)"); 265 | 266 | entity.Property(e => e.HomePage).HasColumnType("VARCHAR(8000)"); 267 | 268 | entity.Property(e => e.Phone).HasColumnType("VARCHAR(8000)"); 269 | 270 | entity.Property(e => e.PostalCode).HasColumnType("VARCHAR(8000)"); 271 | 272 | entity.Property(e => e.Region).HasColumnType("VARCHAR(8000)"); 273 | }); 274 | 275 | modelBuilder.Entity(entity => 276 | { 277 | entity.ToTable("Territory"); 278 | 279 | entity.Property(e => e.Id).HasColumnType("VARCHAR(8000)"); 280 | 281 | entity.Property(e => e.TerritoryDescription).HasColumnType("VARCHAR(8000)"); 282 | }); 283 | 284 | OnModelCreatingPartial(modelBuilder); 285 | } 286 | 287 | partial void OnModelCreatingPartial(ModelBuilder modelBuilder); 288 | } 289 | } 290 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Models/Category.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Category 7 | { 8 | public Category() 9 | { 10 | Products = new HashSet(); 11 | } 12 | 13 | public long Id { get; set; } 14 | public string? CategoryName { get; set; } 15 | public string? Description { get; set; } 16 | 17 | public virtual ICollection Products { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Models/Customer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Customer 7 | { 8 | public Customer() 9 | { 10 | Orders = new HashSet(); 11 | } 12 | 13 | public string Id { get; set; } = null!; 14 | public string? CompanyName { get; set; } 15 | public string? ContactName { get; set; } 16 | public string? ContactTitle { get; set; } 17 | public string? Address { get; set; } 18 | public string? City { get; set; } 19 | public string? Region { get; set; } 20 | public string? PostalCode { get; set; } 21 | public string? Country { get; set; } 22 | public string? Phone { get; set; } 23 | public string? Fax { get; set; } 24 | 25 | public virtual ICollection Orders { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Models/Employee.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Employee 7 | { 8 | public Employee() 9 | { 10 | EmployeeTerritories = new HashSet(); 11 | Orders = new HashSet(); 12 | } 13 | 14 | public long Id { get; set; } 15 | public string? LastName { get; set; } 16 | public string? FirstName { get; set; } 17 | public string? Title { get; set; } 18 | public string? TitleOfCourtesy { get; set; } 19 | public string? BirthDate { get; set; } 20 | public string? HireDate { get; set; } 21 | public string? Address { get; set; } 22 | public string? City { get; set; } 23 | public string? Region { get; set; } 24 | public string? PostalCode { get; set; } 25 | public string? Country { get; set; } 26 | public string? HomePhone { get; set; } 27 | public string? Extension { get; set; } 28 | public string? Notes { get; set; } 29 | public long? ReportsTo { get; set; } 30 | public string? PhotoPath { get; set; } 31 | 32 | public virtual ICollection EmployeeTerritories { get; set; } 33 | public virtual ICollection Orders { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Models/EmployeeTerritory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class EmployeeTerritory 7 | { 8 | public string Id { get; set; } = null!; 9 | public string? TerritoryId { get; set; } 10 | public long? EmployeeId { get; set; } 11 | 12 | public virtual Employee? Employee { get; set; } 13 | public virtual Territory? Territory { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Models/Order.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Order 7 | { 8 | public Order() 9 | { 10 | OrderDetails = new HashSet(); 11 | } 12 | 13 | public long Id { get; set; } 14 | public string? OrderDate { get; set; } 15 | public string? RequiredDate { get; set; } 16 | public string? ShippedDate { get; set; } 17 | public long? ShipVia { get; set; } 18 | public byte[] Freight { get; set; } = null!; 19 | public string? ShipName { get; set; } 20 | public string? ShipAddress { get; set; } 21 | public string? ShipCity { get; set; } 22 | public string? ShipRegion { get; set; } 23 | public string? ShipPostalCode { get; set; } 24 | public string? ShipCountry { get; set; } 25 | public string? CustomerId { get; set; } 26 | public long EmployeeId { get; set; } 27 | 28 | public virtual Customer? Customer { get; set; } 29 | public virtual Employee Employee { get; set; } = null!; 30 | public virtual ICollection OrderDetails { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Models/OrderDetail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class OrderDetail 7 | { 8 | public string Id { get; set; } = null!; 9 | public byte[] UnitPrice { get; set; } = null!; 10 | public long Quantity { get; set; } 11 | public double Discount { get; set; } 12 | public long? ProductId { get; set; } 13 | public long? OrderId { get; set; } 14 | 15 | public virtual Order? Order { get; set; } 16 | public virtual Product? Product { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Models/Product.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Product 7 | { 8 | public Product() 9 | { 10 | OrderDetails = new HashSet(); 11 | } 12 | 13 | public long Id { get; set; } 14 | public string? ProductName { get; set; } 15 | public long? SupplierId { get; set; } 16 | public long? CategoryId { get; set; } 17 | public string? QuantityPerUnit { get; set; } 18 | public byte[] UnitPrice { get; set; } = null!; 19 | public long UnitsInStock { get; set; } 20 | public long UnitsOnOrder { get; set; } 21 | public long ReorderLevel { get; set; } 22 | public long Discontinued { get; set; } 23 | 24 | public virtual Category? Category { get; set; } 25 | public virtual Supplier? Supplier { get; set; } 26 | public virtual ICollection OrderDetails { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Models/ProductDetail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class ProductDetail 7 | { 8 | public long? Id { get; set; } 9 | public string? ProductName { get; set; } 10 | public long? SupplierId { get; set; } 11 | public long? CategoryId { get; set; } 12 | public string? QuantityPerUnit { get; set; } 13 | public byte[]? UnitPrice { get; set; } 14 | public long? UnitsInStock { get; set; } 15 | public long? UnitsOnOrder { get; set; } 16 | public long? ReorderLevel { get; set; } 17 | public long? Discontinued { get; set; } 18 | public string? CategoryName { get; set; } 19 | public string? CategoryDescription { get; set; } 20 | public string? SupplierName { get; set; } 21 | public string? SupplierRegion { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Models/Region.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Region 7 | { 8 | public long Id { get; set; } 9 | public string? RegionDescription { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Models/Shipper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Shipper 7 | { 8 | public long Id { get; set; } 9 | public string? CompanyName { get; set; } 10 | public string? Phone { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Models/Supplier.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Supplier 7 | { 8 | public Supplier() 9 | { 10 | Products = new HashSet(); 11 | } 12 | 13 | public long Id { get; set; } 14 | public string? CompanyName { get; set; } 15 | public string? ContactName { get; set; } 16 | public string? ContactTitle { get; set; } 17 | public string? Address { get; set; } 18 | public string? City { get; set; } 19 | public string? Region { get; set; } 20 | public string? PostalCode { get; set; } 21 | public string? Country { get; set; } 22 | public string? Phone { get; set; } 23 | public string? Fax { get; set; } 24 | public string? HomePage { get; set; } 25 | 26 | public virtual ICollection Products { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Models/Territory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Models 5 | { 6 | public partial class Territory 7 | { 8 | public Territory() 9 | { 10 | EmployeeTerritories = new HashSet(); 11 | } 12 | 13 | public string Id { get; set; } = null!; 14 | public string? TerritoryDescription { get; set; } 15 | public long RegionId { get; set; } 16 | 17 | public virtual ICollection EmployeeTerritories { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Northwind.SQLite.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | runtime; build; native; contentfiles; analyzers; buildtransitive 13 | all 14 | 15 | 16 | 17 | 18 | all 19 | runtime; build; native; contentfiles; analyzers; buildtransitive 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Northwind.SQLite.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31919.166 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Northwind.SQLite", "Northwind.SQLite.csproj", "{3FA5EA0F-72C5-43F7-B743-27C0760E0E5F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3FA5EA0F-72C5-43F7-B743-27C0760E0E5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {3FA5EA0F-72C5-43F7-B743-27C0760E0E5F}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {3FA5EA0F-72C5-43F7-B743-27C0760E0E5F}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {3FA5EA0F-72C5-43F7-B743-27C0760E0E5F}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {8F1C397D-15E5-48B1-A74B-AC49F59417F2} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Newtonsoft.Json; 3 | using Northwind.Data; 4 | 5 | var builder = WebApplication.CreateBuilder(args); 6 | 7 | // Add services to the container. 8 | 9 | builder.Services.AddControllers(); 10 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 11 | builder.Services.AddEndpointsApiExplorer(); 12 | builder.Services.AddSwaggerGen(); 13 | 14 | builder.Services.AddDbContext 15 | (options => options.UseSqlite("Name=NorthwindDB")); 16 | 17 | builder.Services.AddMvc(option => option.EnableEndpointRouting = false) 18 | .AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore); 19 | 20 | 21 | var app = builder.Build(); 22 | 23 | // Configure the HTTP request pipeline. 24 | if (app.Environment.IsDevelopment()) 25 | { 26 | app.UseSwagger(); 27 | app.UseSwaggerUI(); 28 | } 29 | 30 | app.UseHttpsRedirection(); 31 | 32 | app.UseAuthorization(); 33 | 34 | app.MapControllers(); 35 | 36 | app.Run(); 37 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:52269", 8 | "sslPort": 44378 9 | } 10 | }, 11 | "profiles": { 12 | "Northwind.SQLite": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:7238;http://localhost:5238", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.SQLite 2 | { 3 | public class WeatherForecast 4 | { 5 | public DateTime Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 10 | 11 | public string? Summary { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /SQLite/Northwind.SQLite/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "ConnectionStrings": { 10 | "NorthwindDB": "Data source=../Database/northwind.sqlite" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /SQLite/Steps.txt: -------------------------------------------------------------------------------- 1 | Add Connection String => 2 | Data source=../Database/northwind.sqlite 3 | 4 | Packages to install => 5 | dotnet add package Microsoft.EntityFrameworkCore.Design 6 | dotnet add package Microsoft.EntityFrameworkCore.Sqlite 7 | dotnet add package Microsoft.AspNetCore.Mvc.NewtonsoftJson 8 | 9 | Install & Update dotnet EF tool => 10 | dotnet tool install --global dotnet-ef 11 | dotnet tool update --global dotnet-ef 12 | 13 | Scaffold SQLite Database => 14 | dotnet ef dbcontext scaffold Name=NorthwindDB Microsoft.EntityFrameworkCore.Sqlite --output-dir Models --context-dir Data --namespace Northwind.Models --context-namespace Northwind.Data --context NorthwindContext -f --no-onconfiguring --------------------------------------------------------------------------------