├── .gitattributes ├── .gitignore ├── EntityFrameworkNet5.ConsoleApp.ScaffoldDb.Sample ├── Class1.cs ├── EntityFrameworkNet5.ConsoleApp.ScaffoldDb.Sample.csproj ├── FootballLeage_EfCoreContext.cs ├── League.cs └── Team.cs ├── EntityFrameworkNet5.ConsoleApp ├── EntityFrameworkNet5.ConsoleApp.csproj └── Program.cs ├── EntityFrameworkNet5.Data ├── AuditableFootballLeageDbContext.cs ├── Configurations │ └── Entities │ │ ├── CoachConfiguration.cs │ │ ├── LeagueConfiguration.cs │ │ └── TeamConfiguration.cs ├── EntityFrameworkNet5.Data.csproj ├── FootballLeageDbContext.cs ├── FootballLeageDbContext.dgml └── Migrations │ ├── 20210612175329_InitialMigration.Designer.cs │ ├── 20210612175329_InitialMigration.cs │ ├── 20210617003646_AddedMatchesTable.Designer.cs │ ├── 20210617003646_AddedMatchesTable.cs │ ├── 20210617011628_AddedCoachTeamOneToOne.Designer.cs │ ├── 20210617011628_AddedCoachTeamOneToOne.cs │ ├── 20210620192651_AddingTeamDetailsViewAndEarlyMatchFunction.Designer.cs │ ├── 20210620192651_AddingTeamDetailsViewAndEarlyMatchFunction.cs │ ├── 20210620204824_AddingSPGetCoachName.Designer.cs │ ├── 20210620204824_AddingSPGetCoachName.cs │ ├── 20210620211644_AddDeleteTeamByIdSP.Designer.cs │ ├── 20210620211644_AddDeleteTeamByIdSP.cs │ ├── 20210620215933_AddedDefaultTeamsAndCoaches.Designer.cs │ ├── 20210620215933_AddedDefaultTeamsAndCoaches.cs │ ├── 20210622010052_AddedAuditFields.Designer.cs │ ├── 20210622010052_AddedAuditFields.cs │ ├── 20210622232509_AddedValidations.Designer.cs │ ├── 20210622232509_AddedValidations.cs │ └── FootballLeageDbContextModelSnapshot.cs ├── EntityFrameworkNet5.Domain ├── Coach.cs ├── Common │ └── BaseDomainObject.cs ├── EntityFrameworkNet5.Domain.csproj ├── League.cs ├── Match.cs ├── Models │ └── TeamDetail.cs ├── Team.cs └── TeamsCoachesLeaguesView.cs ├── EntityFrameworkNet5.sln └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.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 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /EntityFrameworkNet5.ConsoleApp.ScaffoldDb.Sample/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EntityFrameworkNet5.ConsoleApp.ScaffoldDb.Sample 4 | { 5 | public class Class1 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.ConsoleApp.ScaffoldDb.Sample/EntityFrameworkNet5.ConsoleApp.ScaffoldDb.Sample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | all 11 | runtime; build; native; contentfiles; analyzers; buildtransitive 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.ConsoleApp.ScaffoldDb.Sample/FootballLeage_EfCoreContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Metadata; 4 | 5 | #nullable disable 6 | 7 | namespace EntityFrameworkNet5.ConsoleApp.ScaffoldDb.Sample 8 | { 9 | public partial class FootballLeage_EfCoreContext : DbContext 10 | { 11 | public FootballLeage_EfCoreContext() 12 | { 13 | } 14 | 15 | public FootballLeage_EfCoreContext(DbContextOptions options) 16 | : base(options) 17 | { 18 | } 19 | 20 | public virtual DbSet Leagues { get; set; } 21 | public virtual DbSet Teams { get; set; } 22 | 23 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 24 | { 25 | if (!optionsBuilder.IsConfigured) 26 | { 27 | #warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263. 28 | optionsBuilder.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB; Initial Catalog=FootballLeage_EfCore"); 29 | } 30 | } 31 | 32 | protected override void OnModelCreating(ModelBuilder modelBuilder) 33 | { 34 | modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS"); 35 | 36 | modelBuilder.Entity(entity => 37 | { 38 | entity.HasIndex(e => e.LeagueId, "IX_Teams_LeagueId"); 39 | 40 | entity.HasOne(d => d.League) 41 | .WithMany(p => p.Teams) 42 | .HasForeignKey(d => d.LeagueId); 43 | }); 44 | 45 | OnModelCreatingPartial(modelBuilder); 46 | } 47 | 48 | partial void OnModelCreatingPartial(ModelBuilder modelBuilder); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.ConsoleApp.ScaffoldDb.Sample/League.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | #nullable disable 5 | 6 | namespace EntityFrameworkNet5.ConsoleApp.ScaffoldDb.Sample 7 | { 8 | public partial class League 9 | { 10 | public League() 11 | { 12 | Teams = new HashSet(); 13 | } 14 | 15 | public int Id { get; set; } 16 | public string Name { get; set; } 17 | 18 | public virtual ICollection Teams { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.ConsoleApp.ScaffoldDb.Sample/Team.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | #nullable disable 5 | 6 | namespace EntityFrameworkNet5.ConsoleApp.ScaffoldDb.Sample 7 | { 8 | public partial class Team 9 | { 10 | public int Id { get; set; } 11 | public string Name { get; set; } 12 | public int LeagueId { get; set; } 13 | 14 | public virtual League League { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.ConsoleApp/EntityFrameworkNet5.ConsoleApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.ConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkNet5.Data; 2 | using EntityFrameworkNet5.Domain; 3 | using EntityFrameworkNet5.Domain.Models; 4 | using Microsoft.EntityFrameworkCore; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace EntityFrameworkNet5.ConsoleApp 11 | { 12 | class Program 13 | { 14 | private static FootballLeageDbContext context = new FootballLeageDbContext(); 15 | 16 | static async Task Main(string[] args) 17 | { 18 | /* Simple Insert Operation Methods */ 19 | await AddNewLeague(); 20 | await AddNewTeamsWithLeague(); 21 | 22 | /* Simple Select Queries */ 23 | ////await SimpleSelectQuery(); 24 | 25 | /* Queries With Filters */ 26 | ////await QueryFilters(); 27 | 28 | /* Aggregate Functions */ 29 | ////await AdditionalExecutionMethods(); 30 | 31 | /*Alternative LINQ Syntax*/ 32 | ////await AlternativeLinqSyntax(); 33 | 34 | /* Perform Update */ 35 | await SimpleUpdateLeagueRecord(); 36 | await SimpleUpdateTeamRecord(); 37 | 38 | /* Perform Delete */ 39 | ////await SimpleDelete(); 40 | ////await DeleteWithRelationship(); 41 | 42 | /*Tracking vs No-Tracking*/ 43 | ////await TrackingVsNoTracking(); 44 | 45 | /*Adding Records with relationships*/ 46 | ////Adding OneToMany Related Records 47 | ////await AddNewTeamsWithLeague(); 48 | ////await AddNewTeamWithLeagueId(); 49 | ////await AddNewLeagueWithTeams(); 50 | 51 | ////Adding ManyToMany Records 52 | ////await AddNewMatches(); 53 | 54 | ////Adding OneToOne Records 55 | ////await AddNewCoach(); 56 | 57 | /* Including Related Data - Eager Loading*/ 58 | ////await QueryRelatedRecords(); 59 | 60 | /* Projections to Other Data Types or Ananymous Types */ 61 | ////await SelectOneProperty(); 62 | ////await AnonymousProjection(); 63 | ////await StronglyTypedProjection(); 64 | 65 | /* Filter Based on Related Data */ 66 | ////await FilteringWithRelatedData(); 67 | 68 | /* Querying Views */ 69 | ////await QueryView(); 70 | 71 | /* Query With Raw SQL */ 72 | ////await RawSQLQuery(); 73 | 74 | /* Query Stored Procedures */ 75 | ////await ExecStoredProcedure(); 76 | 77 | /* RAW SQL Non-Query Commands */ 78 | ////await ExecuteNonQueryCommand(); 79 | 80 | Console.WriteLine("Press Any Key To End...."); 81 | Console.ReadKey(); 82 | } 83 | 84 | async static Task ExecuteNonQueryCommand() 85 | { 86 | var teamId = 10; 87 | var affectedRows = await context.Database.ExecuteSqlRawAsync("exec sp_DeleteTeamById {0}", teamId); 88 | 89 | var teamId2 = 12; 90 | var affectedRows2 = await context.Database.ExecuteSqlInterpolatedAsync($"exec sp_DeleteTeamById {teamId2}"); 91 | } 92 | 93 | async static Task ExecStoredProcedure() 94 | { 95 | var teamId = 3; 96 | var result = await context.Coaches.FromSqlRaw("EXEC dbo.sp_GetTeamCoach {0}", teamId).ToListAsync(); 97 | } 98 | 99 | async static Task RawSQLQuery() 100 | { 101 | var name = "AS Roma"; 102 | var teams1 = await context.Teams.FromSqlRaw($"Select * from Teams where name = '{name}'") 103 | .Include(q => q.Coach).ToListAsync(); 104 | 105 | var teams2 = await context.Teams.FromSqlInterpolated($"Select * from Teams where name = {name}").ToListAsync(); 106 | 107 | } 108 | 109 | async static Task QueryView() 110 | { 111 | var details = await context.TeamsCoachesLeagues.ToListAsync(); 112 | } 113 | 114 | async static Task FilteringWithRelatedData() 115 | { 116 | var leagues = await context.Leagues.Where(q => q.Teams.Any(x => x.Name.Contains("Bay"))).ToListAsync(); 117 | } 118 | 119 | async static Task SelectOneProperty() 120 | { 121 | var teams = await context.Teams.Select(q => q.Name).ToListAsync(); 122 | } 123 | 124 | async static Task AnonymousProjection() 125 | { 126 | var teams = await context.Teams.Include(q => q.Coach).Select( 127 | q => 128 | new { 129 | TeamName = q.Name, 130 | CoachName = q.Coach.Name 131 | } 132 | ).ToListAsync(); 133 | 134 | foreach (var item in teams) 135 | { 136 | Console.WriteLine($"Team: {item.TeamName} | Coach: {item.CoachName}"); 137 | } 138 | } 139 | 140 | async static Task StronglyTypedProjection() 141 | { 142 | var teams = await context.Teams.Include(q => q.Coach).Include(q => q.League).Select( 143 | q => 144 | new TeamsCoachesLeaguesView { 145 | Name = q.Name, 146 | CoachName = q.Coach.Name, 147 | LeagueName = q.League.Name 148 | } 149 | ).ToListAsync(); 150 | foreach (var item in teams) 151 | { 152 | Console.WriteLine($"Team: {item.Name} | Coach: {item.CoachName} | League: {item.LeagueName}"); 153 | } 154 | } 155 | 156 | static async Task QueryRelatedRecords() 157 | { 158 | //// Get Many Related Records - Leagues -> Teams 159 | var leagues = await context.Leagues.Include(q => q.Teams).ToListAsync(); 160 | 161 | //// Get One Related Record - Team -> Coach 162 | var team = await context.Teams 163 | .Include(q => q.Coach) 164 | .FirstOrDefaultAsync(q => q.Id == 3); 165 | 166 | //// Get 'Grand Children' Related Record - Team -> Matches -> Home/Away Team 167 | var teamsWithMatchesAndOpponents = await context.Teams 168 | .Include(q => q.AwayMatches).ThenInclude(q => q.HomeTeam).ThenInclude(q => q.Coach) 169 | .Include(q => q.HomeMatches).ThenInclude(q => q.AwayTeam).ThenInclude(q => q.Coach) 170 | .FirstOrDefaultAsync(q => q.Id == 1); 171 | 172 | //// Get Includes with filters 173 | var teams = await context.Teams 174 | .Where(q => q.HomeMatches.Count > 0) 175 | .Include(q => q.Coach) 176 | .ToListAsync(); 177 | } 178 | 179 | 180 | private static async Task TrackingVsNoTracking() 181 | { 182 | var withTracking = await context.Teams.FirstOrDefaultAsync(q => q.Id == 2); 183 | var withNoTracking = await context.Teams.AsNoTracking().FirstOrDefaultAsync(q => q.Id == 8); 184 | 185 | withTracking.Name = "Inter Milan"; 186 | withNoTracking.Name = "Rivoli United"; 187 | 188 | var entriesBeforeSave = context.ChangeTracker.Entries(); 189 | 190 | await context.SaveChangesAsync(); 191 | 192 | var entriesAfterSave = context.ChangeTracker.Entries(); 193 | } 194 | 195 | private static async Task SimpleDelete() 196 | { 197 | var league = await context.Leagues.FindAsync(4); 198 | context.Leagues.Remove(league); 199 | await context.SaveChangesAsync(); 200 | } 201 | 202 | private static async Task DeleteWithRelationship() 203 | { 204 | var league = await context.Leagues.FindAsync(9); 205 | context.Leagues.Remove(league); 206 | await context.SaveChangesAsync(); 207 | } 208 | 209 | private static async Task SimpleUpdateTeamRecord() 210 | { 211 | var team = new Team 212 | { 213 | Id = 7, 214 | Name = "Seba United FC", 215 | LeagueId = 2 216 | }; 217 | context.Teams.Update(team); 218 | await context.SaveChangesAsync("Test Update User"); 219 | } 220 | 221 | private static async Task GetRecord() 222 | { 223 | ////Retrieve Record 224 | var league = await context.Leagues.FindAsync(3); 225 | Console.WriteLine($"{league.Id} - {league.Name}"); 226 | } 227 | 228 | private static async Task SimpleUpdateLeagueRecord() 229 | { 230 | ////Retrieve Record 231 | var league = await context.Leagues.FindAsync(20); 232 | ///Make Record Changes 233 | league.Name = "Scottish Premiership"; 234 | ///Save Changes 235 | await context.SaveChangesAsync(); 236 | 237 | await GetRecord(); 238 | 239 | } 240 | 241 | static async Task AlternativeLinqSyntax() 242 | { 243 | Console.Write($"Enter Team Name (Or Part Of): "); 244 | var teamName = Console.ReadLine(); 245 | var teams = await (from i in context.Teams 246 | where EF.Functions.Like(i.Name, $"%{teamName}%") 247 | select i).ToListAsync(); 248 | 249 | foreach (var team in teams) 250 | { 251 | Console.WriteLine($"{team.Id} - {team.Name}"); 252 | } 253 | } 254 | 255 | static async Task AdditionalExecutionMethods() 256 | { 257 | //// These methods also have non-async 258 | var leagues = context.Leagues; 259 | var list = await leagues.ToListAsync(); 260 | var first = await leagues.FirstAsync(); 261 | var firstOrDefault = await leagues.FirstOrDefaultAsync(); 262 | var single = await leagues.SingleAsync(); 263 | var singleOrDefault = await leagues.SingleOrDefaultAsync(); 264 | 265 | var count = await leagues.CountAsync(); 266 | var longCount = await leagues.LongCountAsync(); 267 | var min = await leagues.MinAsync(); 268 | var max = await leagues.MaxAsync(); 269 | 270 | //// DbSet Method that will execute 271 | var league = await leagues.FindAsync(1); 272 | 273 | } 274 | 275 | static async Task QueryFilters() 276 | { 277 | Console.Write($"Enter League Name (Or Part Of): "); 278 | var leagueName = Console.ReadLine(); 279 | var exactMatches= await context.Leagues.Where(q => q.Name.Equals(leagueName)).ToListAsync(); 280 | foreach (var league in exactMatches) 281 | { 282 | Console.WriteLine($"{league.Id} - {league.Name}"); 283 | } 284 | 285 | ////var partialMatches = await context.Leagues.Where(q => q.Name.Contains(leagueName)).ToListAsync(); 286 | var partialMatches = await context.Leagues.Where(q => EF.Functions.Like(q.Name, $"%{leagueName}%")).ToListAsync(); 287 | foreach (var league in partialMatches) 288 | { 289 | Console.WriteLine($"{league.Id} - {league.Name}"); 290 | } 291 | } 292 | 293 | static async Task SimpleSelectQuery() 294 | { 295 | //// Smartest most efficient way to get results 296 | var leagues = await context.Leagues.ToListAsync(); 297 | foreach (var league in leagues) 298 | { 299 | Console.WriteLine($"{league.Id} - {league.Name}"); 300 | } 301 | 302 | //// Inefficient way to get results. Keeps connection open until completed and might create lock on table 303 | ////foreach (var league in context.Leagues) 304 | ////{ 305 | //// Console.WriteLine($"{league.Id} - {league.Name}"); 306 | ////} 307 | 308 | } 309 | 310 | static async Task AddNewLeague() 311 | { 312 | //// Adding a new League Object 313 | var league = new League { Name = "Audit Testing League" }; 314 | await context.Leagues.AddAsync(league); 315 | await context.SaveChangesAsync("Test Audit Create User"); 316 | 317 | //// Function To add new teams related to the new league object. 318 | await AddTeamsWithLeague(league); 319 | await context.SaveChangesAsync(); 320 | } 321 | 322 | static async Task AddTeamsWithLeague(League league) 323 | { 324 | var teams = new List 325 | { 326 | new Team 327 | { 328 | Name = "Juventus", 329 | LeagueId = league.Id 330 | }, 331 | new Team 332 | { 333 | Name = "AC Milan", 334 | LeagueId = league.Id 335 | }, 336 | new Team 337 | { 338 | Name = "AS Roma", 339 | League = league 340 | } 341 | }; 342 | 343 | //// Operation to add multiple objects to database in one call. 344 | await context.AddRangeAsync(teams); 345 | } 346 | 347 | static async Task AddNewTeamsWithLeague() 348 | { 349 | var league = new League { Name = "Bundesliga" }; 350 | var team = new Team { Name = "Bayern Munich", League = league }; 351 | await context.AddAsync(team); 352 | await context.SaveChangesAsync(); 353 | } 354 | 355 | static async Task AddNewTeamWithLeagueId() 356 | { 357 | var team = new Team { Name = "Fiorentina", LeagueId = 8 }; 358 | await context.AddAsync(team); 359 | await context.SaveChangesAsync(); 360 | } 361 | 362 | static async Task AddNewLeagueWithTeams() 363 | { 364 | var teams = new List { 365 | new Team 366 | { 367 | Name = "Rivoli United" 368 | }, 369 | new Team 370 | { 371 | Name = "Waterhouse FC" 372 | }, 373 | }; 374 | var league = new League { Name = "CIFA", Teams = teams }; 375 | await context.AddAsync(league); 376 | await context.SaveChangesAsync(); 377 | } 378 | 379 | static async Task AddNewMatches() 380 | { 381 | var matches = new List 382 | { 383 | new Match 384 | { 385 | AwayTeamId = 1, HomeTeamId = 2, Date = new DateTime(2021, 10, 28) 386 | }, 387 | new Match 388 | { 389 | AwayTeamId = 8, HomeTeamId = 7, Date = DateTime.Now 390 | }, 391 | new Match 392 | { 393 | AwayTeamId = 8, HomeTeamId = 7, Date = DateTime.Now 394 | } 395 | }; 396 | await context.AddRangeAsync(matches); 397 | await context.SaveChangesAsync(); 398 | } 399 | private static async Task AddNewCoach() 400 | { 401 | var coach1 = new Coach { Name = "Jose Mourinho", TeamId = 3 }; 402 | 403 | await context.AddAsync(coach1); 404 | 405 | var coach2 = new Coach { Name = "Antonio Conte" }; 406 | 407 | await context.AddAsync(coach2); 408 | await context.SaveChangesAsync(); 409 | } 410 | } 411 | } 412 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/AuditableFootballLeageDbContext.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkNet5.Data.Configurations.Entities; 2 | using EntityFrameworkNet5.Domain; 3 | using EntityFrameworkNet5.Domain.Common; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.Extensions.Logging; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading; 11 | using System.Threading.Tasks; 12 | 13 | namespace EntityFrameworkNet5.Data 14 | { 15 | public abstract class AuditableFootballLeageDbContext : DbContext 16 | { 17 | public async Task SaveChangesAsync(string username) 18 | { 19 | var entries = ChangeTracker.Entries().Where(q => q.State == EntityState.Added || q.State == EntityState.Modified); 20 | 21 | foreach (var entry in entries) 22 | { 23 | var auditableObject = (BaseDomainObject)entry.Entity; 24 | auditableObject.ModifiedDate = DateTime.Now; 25 | auditableObject.ModifiedBy = username; 26 | 27 | if (entry.State == EntityState.Added) 28 | { 29 | auditableObject.CreatedDate = DateTime.Now; 30 | auditableObject.CreatedBy = username; 31 | } 32 | } 33 | 34 | return await base.SaveChangesAsync(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Configurations/Entities/CoachConfiguration.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkNet5.Domain; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace EntityFrameworkNet5.Data.Configurations.Entities 11 | { 12 | public class CoachConfiguration : IEntityTypeConfiguration 13 | { 14 | public void Configure(EntityTypeBuilder builder) 15 | { 16 | builder.Property(p => p.Name).HasMaxLength(50); 17 | builder.HasIndex(h => new { h.Name, h.TeamId }).IsUnique(); 18 | builder.HasData( 19 | new Coach 20 | { 21 | Id = 20, 22 | Name = "Trevoir Williams", 23 | TeamId = 20 24 | }, 25 | new Coach 26 | { 27 | Id = 21, 28 | Name = "Trevoir Williams - Sample 1", 29 | TeamId = 21 30 | }, new Coach 31 | { 32 | Id = 22, 33 | Name = "Trevoir Williams - Sample 2", 34 | TeamId = 22 35 | } 36 | ); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Configurations/Entities/LeagueConfiguration.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkNet5.Domain; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace EntityFrameworkNet5.Data.Configurations.Entities 11 | { 12 | public class LeagueConfiguration : IEntityTypeConfiguration 13 | { 14 | public void Configure(EntityTypeBuilder builder) 15 | { 16 | builder.Property(p => p.Name).HasMaxLength(50); 17 | builder.HasIndex(h => h.Name); 18 | 19 | builder.HasData( 20 | new League 21 | { 22 | Id = 20, 23 | Name = "Sample League", 24 | } 25 | ); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Configurations/Entities/TeamConfiguration.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkNet5.Domain; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace EntityFrameworkNet5.Data.Configurations.Entities 11 | { 12 | public class TeamConfiguration : IEntityTypeConfiguration 13 | { 14 | public void Configure(EntityTypeBuilder builder) 15 | { 16 | builder.Property(p => p.Name).HasMaxLength(50); 17 | builder.HasIndex(h => h.Name).IsUnique(); 18 | builder.HasMany(m => m.HomeMatches) 19 | .WithOne(m => m.HomeTeam) 20 | .HasForeignKey(m => m.HomeTeamId) 21 | .IsRequired() 22 | .OnDelete(DeleteBehavior.Restrict); 23 | 24 | builder.HasMany(m => m.AwayMatches) 25 | .WithOne(m => m.AwayTeam) 26 | .HasForeignKey(m => m.AwayTeamId) 27 | .IsRequired() 28 | .OnDelete(DeleteBehavior.Restrict); 29 | 30 | builder.HasData( 31 | new Team 32 | { 33 | Id = 20, 34 | Name = "Trevoir Williams - Sample Team", 35 | LeagueId = 20 36 | }, 37 | new Team 38 | { 39 | Id = 21, 40 | Name = "Trevoir Williams - Sample Team", 41 | LeagueId = 20 42 | 43 | }, 44 | new Team 45 | { 46 | Id = 22, 47 | Name = "Trevoir Williams - Sample Team", 48 | LeagueId = 20 49 | 50 | } 51 | ); 52 | 53 | 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/EntityFrameworkNet5.Data.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | all 10 | runtime; build; native; contentfiles; analyzers; buildtransitive 11 | 12 | 13 | 14 | all 15 | runtime; build; native; contentfiles; analyzers; buildtransitive 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/FootballLeageDbContext.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkNet5.Data.Configurations.Entities; 2 | using EntityFrameworkNet5.Domain; 3 | using EntityFrameworkNet5.Domain.Common; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.Extensions.Logging; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading; 11 | using System.Threading.Tasks; 12 | 13 | namespace EntityFrameworkNet5.Data 14 | { 15 | public class FootballLeageDbContext : AuditableFootballLeageDbContext 16 | { 17 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 18 | { 19 | optionsBuilder.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB; Initial Catalog=FootballLeage_EfCore") 20 | .LogTo(Console.WriteLine, new[] { DbLoggerCategory.Database.Command.Name }, LogLevel.Information ) 21 | .EnableSensitiveDataLogging(); 22 | } 23 | 24 | protected override void OnModelCreating(ModelBuilder modelBuilder) 25 | { 26 | modelBuilder.Entity().HasNoKey().ToView("TeamsCoachesLeagues"); 27 | modelBuilder.ApplyConfiguration(new LeagueConfiguration()); 28 | modelBuilder.ApplyConfiguration(new TeamConfiguration()); 29 | modelBuilder.ApplyConfiguration(new CoachConfiguration()); 30 | 31 | } 32 | 33 | 34 | public DbSet Teams { get; set; } 35 | public DbSet Leagues { get; set; } 36 | public DbSet Matches { get; set; } 37 | public DbSet Coaches { get; set; } 38 | public DbSet TeamsCoachesLeagues { get; set; } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/FootballLeageDbContext.dgml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | 12 | 17 | 20 | 21 | 23 | 25 | 30 | 33 | 34 | 36 | 41 | 44 | 45 | 46 | 48 | 50 | 52 | 53 | 56 | 57 | 58 | 59 | 60 | 62 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 101 | 105 | 109 | 113 | 117 | 121 | 125 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210612175329_InitialMigration.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using EntityFrameworkNet5.Data; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Infrastructure; 5 | using Microsoft.EntityFrameworkCore.Metadata; 6 | using Microsoft.EntityFrameworkCore.Migrations; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | namespace EntityFrameworkNet5.Data.Migrations 10 | { 11 | [DbContext(typeof(FootballLeageDbContext))] 12 | [Migration("20210612175329_InitialMigration")] 13 | partial class InitialMigration 14 | { 15 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 16 | { 17 | #pragma warning disable 612, 618 18 | modelBuilder 19 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 20 | .HasAnnotation("ProductVersion", "5.0.7") 21 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 22 | 23 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 24 | { 25 | b.Property("Id") 26 | .ValueGeneratedOnAdd() 27 | .HasColumnType("int") 28 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 29 | 30 | b.Property("Name") 31 | .HasColumnType("nvarchar(max)"); 32 | 33 | b.HasKey("Id"); 34 | 35 | b.ToTable("Leagues"); 36 | }); 37 | 38 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 39 | { 40 | b.Property("Id") 41 | .ValueGeneratedOnAdd() 42 | .HasColumnType("int") 43 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 44 | 45 | b.Property("LeagueId") 46 | .HasColumnType("int"); 47 | 48 | b.Property("Name") 49 | .HasColumnType("nvarchar(max)"); 50 | 51 | b.HasKey("Id"); 52 | 53 | b.HasIndex("LeagueId"); 54 | 55 | b.ToTable("Teams"); 56 | }); 57 | 58 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 59 | { 60 | b.HasOne("EntityFrameworkNet5.Domain.League", "League") 61 | .WithMany() 62 | .HasForeignKey("LeagueId") 63 | .OnDelete(DeleteBehavior.Cascade) 64 | .IsRequired(); 65 | 66 | b.Navigation("League"); 67 | }); 68 | #pragma warning restore 612, 618 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210612175329_InitialMigration.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | namespace EntityFrameworkNet5.Data.Migrations 4 | { 5 | public partial class InitialMigration : Migration 6 | { 7 | protected override void Up(MigrationBuilder migrationBuilder) 8 | { 9 | migrationBuilder.CreateTable( 10 | name: "Leagues", 11 | columns: table => new 12 | { 13 | Id = table.Column(type: "int", nullable: false) 14 | .Annotation("SqlServer:Identity", "1, 1"), 15 | Name = table.Column(type: "nvarchar(max)", nullable: true) 16 | }, 17 | constraints: table => 18 | { 19 | table.PrimaryKey("PK_Leagues", x => x.Id); 20 | }); 21 | 22 | migrationBuilder.CreateTable( 23 | name: "Teams", 24 | columns: table => new 25 | { 26 | Id = table.Column(type: "int", nullable: false) 27 | .Annotation("SqlServer:Identity", "1, 1"), 28 | Name = table.Column(type: "nvarchar(max)", nullable: true), 29 | LeagueId = table.Column(type: "int", nullable: false) 30 | }, 31 | constraints: table => 32 | { 33 | table.PrimaryKey("PK_Teams", x => x.Id); 34 | table.ForeignKey( 35 | name: "FK_Teams_Leagues_LeagueId", 36 | column: x => x.LeagueId, 37 | principalTable: "Leagues", 38 | principalColumn: "Id", 39 | onDelete: ReferentialAction.Cascade); 40 | }); 41 | 42 | migrationBuilder.CreateIndex( 43 | name: "IX_Teams_LeagueId", 44 | table: "Teams", 45 | column: "LeagueId"); 46 | } 47 | 48 | protected override void Down(MigrationBuilder migrationBuilder) 49 | { 50 | migrationBuilder.DropTable( 51 | name: "Teams"); 52 | 53 | migrationBuilder.DropTable( 54 | name: "Leagues"); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210617003646_AddedMatchesTable.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using EntityFrameworkNet5.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace EntityFrameworkNet5.Data.Migrations 11 | { 12 | [DbContext(typeof(FootballLeageDbContext))] 13 | [Migration("20210617003646_AddedMatchesTable")] 14 | partial class AddedMatchesTable 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 21 | .HasAnnotation("ProductVersion", "5.0.7") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("int") 29 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 30 | 31 | b.Property("Name") 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.HasKey("Id"); 35 | 36 | b.ToTable("Leagues"); 37 | }); 38 | 39 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 40 | { 41 | b.Property("Id") 42 | .ValueGeneratedOnAdd() 43 | .HasColumnType("int") 44 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 45 | 46 | b.Property("AwayTeamId") 47 | .HasColumnType("int"); 48 | 49 | b.Property("Date") 50 | .HasColumnType("datetime2"); 51 | 52 | b.Property("HomeTeamId") 53 | .HasColumnType("int"); 54 | 55 | b.HasKey("Id"); 56 | 57 | b.HasIndex("AwayTeamId"); 58 | 59 | b.HasIndex("HomeTeamId"); 60 | 61 | b.ToTable("Matches"); 62 | }); 63 | 64 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 65 | { 66 | b.Property("Id") 67 | .ValueGeneratedOnAdd() 68 | .HasColumnType("int") 69 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 70 | 71 | b.Property("LeagueId") 72 | .HasColumnType("int"); 73 | 74 | b.Property("Name") 75 | .HasColumnType("nvarchar(max)"); 76 | 77 | b.HasKey("Id"); 78 | 79 | b.HasIndex("LeagueId"); 80 | 81 | b.ToTable("Teams"); 82 | }); 83 | 84 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 85 | { 86 | b.HasOne("EntityFrameworkNet5.Domain.Team", "AwayTeam") 87 | .WithMany("AwayMatches") 88 | .HasForeignKey("AwayTeamId") 89 | .OnDelete(DeleteBehavior.Restrict) 90 | .IsRequired(); 91 | 92 | b.HasOne("EntityFrameworkNet5.Domain.Team", "HomeTeam") 93 | .WithMany("HomeMatches") 94 | .HasForeignKey("HomeTeamId") 95 | .OnDelete(DeleteBehavior.Restrict) 96 | .IsRequired(); 97 | 98 | b.Navigation("AwayTeam"); 99 | 100 | b.Navigation("HomeTeam"); 101 | }); 102 | 103 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 104 | { 105 | b.HasOne("EntityFrameworkNet5.Domain.League", "League") 106 | .WithMany("Teams") 107 | .HasForeignKey("LeagueId") 108 | .OnDelete(DeleteBehavior.Cascade) 109 | .IsRequired(); 110 | 111 | b.Navigation("League"); 112 | }); 113 | 114 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 115 | { 116 | b.Navigation("Teams"); 117 | }); 118 | 119 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 120 | { 121 | b.Navigation("AwayMatches"); 122 | 123 | b.Navigation("HomeMatches"); 124 | }); 125 | #pragma warning restore 612, 618 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210617003646_AddedMatchesTable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | namespace EntityFrameworkNet5.Data.Migrations 5 | { 6 | public partial class AddedMatchesTable : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.CreateTable( 11 | name: "Matches", 12 | columns: table => new 13 | { 14 | Id = table.Column(type: "int", nullable: false) 15 | .Annotation("SqlServer:Identity", "1, 1"), 16 | HomeTeamId = table.Column(type: "int", nullable: false), 17 | AwayTeamId = table.Column(type: "int", nullable: false), 18 | Date = table.Column(type: "datetime2", nullable: false) 19 | }, 20 | constraints: table => 21 | { 22 | table.PrimaryKey("PK_Matches", x => x.Id); 23 | table.ForeignKey( 24 | name: "FK_Matches_Teams_AwayTeamId", 25 | column: x => x.AwayTeamId, 26 | principalTable: "Teams", 27 | principalColumn: "Id", 28 | onDelete: ReferentialAction.Restrict); 29 | table.ForeignKey( 30 | name: "FK_Matches_Teams_HomeTeamId", 31 | column: x => x.HomeTeamId, 32 | principalTable: "Teams", 33 | principalColumn: "Id", 34 | onDelete: ReferentialAction.Restrict); 35 | }); 36 | 37 | migrationBuilder.CreateIndex( 38 | name: "IX_Matches_AwayTeamId", 39 | table: "Matches", 40 | column: "AwayTeamId"); 41 | 42 | migrationBuilder.CreateIndex( 43 | name: "IX_Matches_HomeTeamId", 44 | table: "Matches", 45 | column: "HomeTeamId"); 46 | } 47 | 48 | protected override void Down(MigrationBuilder migrationBuilder) 49 | { 50 | migrationBuilder.DropTable( 51 | name: "Matches"); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210617011628_AddedCoachTeamOneToOne.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using EntityFrameworkNet5.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace EntityFrameworkNet5.Data.Migrations 11 | { 12 | [DbContext(typeof(FootballLeageDbContext))] 13 | [Migration("20210617011628_AddedCoachTeamOneToOne")] 14 | partial class AddedCoachTeamOneToOne 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 21 | .HasAnnotation("ProductVersion", "5.0.7") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("int") 29 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 30 | 31 | b.Property("Name") 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("TeamId") 35 | .HasColumnType("int"); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.HasIndex("TeamId") 40 | .IsUnique() 41 | .HasFilter("[TeamId] IS NOT NULL"); 42 | 43 | b.ToTable("Coaches"); 44 | }); 45 | 46 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 47 | { 48 | b.Property("Id") 49 | .ValueGeneratedOnAdd() 50 | .HasColumnType("int") 51 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 52 | 53 | b.Property("Name") 54 | .HasColumnType("nvarchar(max)"); 55 | 56 | b.HasKey("Id"); 57 | 58 | b.ToTable("Leagues"); 59 | }); 60 | 61 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 62 | { 63 | b.Property("Id") 64 | .ValueGeneratedOnAdd() 65 | .HasColumnType("int") 66 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 67 | 68 | b.Property("AwayTeamId") 69 | .HasColumnType("int"); 70 | 71 | b.Property("Date") 72 | .HasColumnType("datetime2"); 73 | 74 | b.Property("HomeTeamId") 75 | .HasColumnType("int"); 76 | 77 | b.HasKey("Id"); 78 | 79 | b.HasIndex("AwayTeamId"); 80 | 81 | b.HasIndex("HomeTeamId"); 82 | 83 | b.ToTable("Matches"); 84 | }); 85 | 86 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 87 | { 88 | b.Property("Id") 89 | .ValueGeneratedOnAdd() 90 | .HasColumnType("int") 91 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 92 | 93 | b.Property("LeagueId") 94 | .HasColumnType("int"); 95 | 96 | b.Property("Name") 97 | .HasColumnType("nvarchar(max)"); 98 | 99 | b.HasKey("Id"); 100 | 101 | b.HasIndex("LeagueId"); 102 | 103 | b.ToTable("Teams"); 104 | }); 105 | 106 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 107 | { 108 | b.HasOne("EntityFrameworkNet5.Domain.Team", "Team") 109 | .WithOne("Coach") 110 | .HasForeignKey("EntityFrameworkNet5.Domain.Coach", "TeamId"); 111 | 112 | b.Navigation("Team"); 113 | }); 114 | 115 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 116 | { 117 | b.HasOne("EntityFrameworkNet5.Domain.Team", "AwayTeam") 118 | .WithMany("AwayMatches") 119 | .HasForeignKey("AwayTeamId") 120 | .OnDelete(DeleteBehavior.Restrict) 121 | .IsRequired(); 122 | 123 | b.HasOne("EntityFrameworkNet5.Domain.Team", "HomeTeam") 124 | .WithMany("HomeMatches") 125 | .HasForeignKey("HomeTeamId") 126 | .OnDelete(DeleteBehavior.Restrict) 127 | .IsRequired(); 128 | 129 | b.Navigation("AwayTeam"); 130 | 131 | b.Navigation("HomeTeam"); 132 | }); 133 | 134 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 135 | { 136 | b.HasOne("EntityFrameworkNet5.Domain.League", "League") 137 | .WithMany("Teams") 138 | .HasForeignKey("LeagueId") 139 | .OnDelete(DeleteBehavior.Cascade) 140 | .IsRequired(); 141 | 142 | b.Navigation("League"); 143 | }); 144 | 145 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 146 | { 147 | b.Navigation("Teams"); 148 | }); 149 | 150 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 151 | { 152 | b.Navigation("AwayMatches"); 153 | 154 | b.Navigation("Coach"); 155 | 156 | b.Navigation("HomeMatches"); 157 | }); 158 | #pragma warning restore 612, 618 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210617011628_AddedCoachTeamOneToOne.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | namespace EntityFrameworkNet5.Data.Migrations 4 | { 5 | public partial class AddedCoachTeamOneToOne : Migration 6 | { 7 | protected override void Up(MigrationBuilder migrationBuilder) 8 | { 9 | migrationBuilder.CreateTable( 10 | name: "Coaches", 11 | columns: table => new 12 | { 13 | Id = table.Column(type: "int", nullable: false) 14 | .Annotation("SqlServer:Identity", "1, 1"), 15 | Name = table.Column(type: "nvarchar(max)", nullable: true), 16 | TeamId = table.Column(type: "int", nullable: true) 17 | }, 18 | constraints: table => 19 | { 20 | table.PrimaryKey("PK_Coaches", x => x.Id); 21 | table.ForeignKey( 22 | name: "FK_Coaches_Teams_TeamId", 23 | column: x => x.TeamId, 24 | principalTable: "Teams", 25 | principalColumn: "Id", 26 | onDelete: ReferentialAction.Restrict); 27 | }); 28 | 29 | migrationBuilder.CreateIndex( 30 | name: "IX_Coaches_TeamId", 31 | table: "Coaches", 32 | column: "TeamId", 33 | unique: true, 34 | filter: "[TeamId] IS NOT NULL"); 35 | } 36 | 37 | protected override void Down(MigrationBuilder migrationBuilder) 38 | { 39 | migrationBuilder.DropTable( 40 | name: "Coaches"); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210620192651_AddingTeamDetailsViewAndEarlyMatchFunction.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using EntityFrameworkNet5.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace EntityFrameworkNet5.Data.Migrations 11 | { 12 | [DbContext(typeof(FootballLeageDbContext))] 13 | [Migration("20210620192651_AddingTeamDetailsViewAndEarlyMatchFunction")] 14 | partial class AddingTeamDetailsViewAndEarlyMatchFunction 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 21 | .HasAnnotation("ProductVersion", "5.0.7") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("int") 29 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 30 | 31 | b.Property("Name") 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("TeamId") 35 | .HasColumnType("int"); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.HasIndex("TeamId") 40 | .IsUnique() 41 | .HasFilter("[TeamId] IS NOT NULL"); 42 | 43 | b.ToTable("Coaches"); 44 | }); 45 | 46 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 47 | { 48 | b.Property("Id") 49 | .ValueGeneratedOnAdd() 50 | .HasColumnType("int") 51 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 52 | 53 | b.Property("Name") 54 | .HasColumnType("nvarchar(max)"); 55 | 56 | b.HasKey("Id"); 57 | 58 | b.ToTable("Leagues"); 59 | }); 60 | 61 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 62 | { 63 | b.Property("Id") 64 | .ValueGeneratedOnAdd() 65 | .HasColumnType("int") 66 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 67 | 68 | b.Property("AwayTeamId") 69 | .HasColumnType("int"); 70 | 71 | b.Property("Date") 72 | .HasColumnType("datetime2"); 73 | 74 | b.Property("HomeTeamId") 75 | .HasColumnType("int"); 76 | 77 | b.HasKey("Id"); 78 | 79 | b.HasIndex("AwayTeamId"); 80 | 81 | b.HasIndex("HomeTeamId"); 82 | 83 | b.ToTable("Matches"); 84 | }); 85 | 86 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 87 | { 88 | b.Property("Id") 89 | .ValueGeneratedOnAdd() 90 | .HasColumnType("int") 91 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 92 | 93 | b.Property("LeagueId") 94 | .HasColumnType("int"); 95 | 96 | b.Property("Name") 97 | .HasColumnType("nvarchar(max)"); 98 | 99 | b.HasKey("Id"); 100 | 101 | b.HasIndex("LeagueId"); 102 | 103 | b.ToTable("Teams"); 104 | }); 105 | 106 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 107 | { 108 | b.HasOne("EntityFrameworkNet5.Domain.Team", "Team") 109 | .WithOne("Coach") 110 | .HasForeignKey("EntityFrameworkNet5.Domain.Coach", "TeamId"); 111 | 112 | b.Navigation("Team"); 113 | }); 114 | 115 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 116 | { 117 | b.HasOne("EntityFrameworkNet5.Domain.Team", "AwayTeam") 118 | .WithMany("AwayMatches") 119 | .HasForeignKey("AwayTeamId") 120 | .OnDelete(DeleteBehavior.Restrict) 121 | .IsRequired(); 122 | 123 | b.HasOne("EntityFrameworkNet5.Domain.Team", "HomeTeam") 124 | .WithMany("HomeMatches") 125 | .HasForeignKey("HomeTeamId") 126 | .OnDelete(DeleteBehavior.Restrict) 127 | .IsRequired(); 128 | 129 | b.Navigation("AwayTeam"); 130 | 131 | b.Navigation("HomeTeam"); 132 | }); 133 | 134 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 135 | { 136 | b.HasOne("EntityFrameworkNet5.Domain.League", "League") 137 | .WithMany("Teams") 138 | .HasForeignKey("LeagueId") 139 | .OnDelete(DeleteBehavior.Cascade) 140 | .IsRequired(); 141 | 142 | b.Navigation("League"); 143 | }); 144 | 145 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 146 | { 147 | b.Navigation("Teams"); 148 | }); 149 | 150 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 151 | { 152 | b.Navigation("AwayMatches"); 153 | 154 | b.Navigation("Coach"); 155 | 156 | b.Navigation("HomeMatches"); 157 | }); 158 | #pragma warning restore 612, 618 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210620192651_AddingTeamDetailsViewAndEarlyMatchFunction.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | namespace EntityFrameworkNet5.Data.Migrations 4 | { 5 | public partial class AddingTeamDetailsViewAndEarlyMatchFunction : Migration 6 | { 7 | protected override void Up(MigrationBuilder migrationBuilder) 8 | { 9 | migrationBuilder.Sql(@"CREATE FUNCTION [dbo].[GetEarliestMatch] (@teamId int) 10 | RETURNS datetime 11 | BEGIN 12 | DECLARE @result datetime 13 | SELECT TOP 1 @result = date 14 | FROM [dbo].[Matches] 15 | order by Date 16 | return @result 17 | END"); 18 | migrationBuilder.Sql(@"CREATE VIEW [dbo].[TeamsCoachesLeagues] 19 | AS 20 | SELECT t.Name, c.Name AS CoachName, l.Name AS LeagueName 21 | FROM dbo.Teams AS t LEFT OUTER JOIN 22 | dbo.Coaches AS c ON t.Id = c.TeamId INNER JOIN 23 | dbo.Leagues AS l ON t.LeagueId = l.Id" 24 | ); 25 | } 26 | 27 | protected override void Down(MigrationBuilder migrationBuilder) 28 | { 29 | migrationBuilder.Sql(@"DROP VIEW [dbo].[TeamsCoachesLeagues]"); 30 | migrationBuilder.Sql(@"DROP Function [dbo].[GetEarliestMatch]"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210620204824_AddingSPGetCoachName.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using EntityFrameworkNet5.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace EntityFrameworkNet5.Data.Migrations 11 | { 12 | [DbContext(typeof(FootballLeageDbContext))] 13 | [Migration("20210620204824_AddingSPGetCoachName")] 14 | partial class AddingSPGetCoachName 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 21 | .HasAnnotation("ProductVersion", "5.0.7") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("int") 29 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 30 | 31 | b.Property("Name") 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("TeamId") 35 | .HasColumnType("int"); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.HasIndex("TeamId") 40 | .IsUnique() 41 | .HasFilter("[TeamId] IS NOT NULL"); 42 | 43 | b.ToTable("Coaches"); 44 | }); 45 | 46 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 47 | { 48 | b.Property("Id") 49 | .ValueGeneratedOnAdd() 50 | .HasColumnType("int") 51 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 52 | 53 | b.Property("Name") 54 | .HasColumnType("nvarchar(max)"); 55 | 56 | b.HasKey("Id"); 57 | 58 | b.ToTable("Leagues"); 59 | }); 60 | 61 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 62 | { 63 | b.Property("Id") 64 | .ValueGeneratedOnAdd() 65 | .HasColumnType("int") 66 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 67 | 68 | b.Property("AwayTeamId") 69 | .HasColumnType("int"); 70 | 71 | b.Property("Date") 72 | .HasColumnType("datetime2"); 73 | 74 | b.Property("HomeTeamId") 75 | .HasColumnType("int"); 76 | 77 | b.HasKey("Id"); 78 | 79 | b.HasIndex("AwayTeamId"); 80 | 81 | b.HasIndex("HomeTeamId"); 82 | 83 | b.ToTable("Matches"); 84 | }); 85 | 86 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 87 | { 88 | b.Property("Id") 89 | .ValueGeneratedOnAdd() 90 | .HasColumnType("int") 91 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 92 | 93 | b.Property("LeagueId") 94 | .HasColumnType("int"); 95 | 96 | b.Property("Name") 97 | .HasColumnType("nvarchar(max)"); 98 | 99 | b.HasKey("Id"); 100 | 101 | b.HasIndex("LeagueId"); 102 | 103 | b.ToTable("Teams"); 104 | }); 105 | 106 | modelBuilder.Entity("EntityFrameworkNet5.Domain.TeamsCoachesLeaguesView", b => 107 | { 108 | b.Property("CoachName") 109 | .HasColumnType("nvarchar(max)"); 110 | 111 | b.Property("LeagueName") 112 | .HasColumnType("nvarchar(max)"); 113 | 114 | b.Property("Name") 115 | .HasColumnType("nvarchar(max)"); 116 | 117 | b.ToView("TeamsCoachesLeagues"); 118 | }); 119 | 120 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 121 | { 122 | b.HasOne("EntityFrameworkNet5.Domain.Team", "Team") 123 | .WithOne("Coach") 124 | .HasForeignKey("EntityFrameworkNet5.Domain.Coach", "TeamId"); 125 | 126 | b.Navigation("Team"); 127 | }); 128 | 129 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 130 | { 131 | b.HasOne("EntityFrameworkNet5.Domain.Team", "AwayTeam") 132 | .WithMany("AwayMatches") 133 | .HasForeignKey("AwayTeamId") 134 | .OnDelete(DeleteBehavior.Restrict) 135 | .IsRequired(); 136 | 137 | b.HasOne("EntityFrameworkNet5.Domain.Team", "HomeTeam") 138 | .WithMany("HomeMatches") 139 | .HasForeignKey("HomeTeamId") 140 | .OnDelete(DeleteBehavior.Restrict) 141 | .IsRequired(); 142 | 143 | b.Navigation("AwayTeam"); 144 | 145 | b.Navigation("HomeTeam"); 146 | }); 147 | 148 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 149 | { 150 | b.HasOne("EntityFrameworkNet5.Domain.League", "League") 151 | .WithMany("Teams") 152 | .HasForeignKey("LeagueId") 153 | .OnDelete(DeleteBehavior.Cascade) 154 | .IsRequired(); 155 | 156 | b.Navigation("League"); 157 | }); 158 | 159 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 160 | { 161 | b.Navigation("Teams"); 162 | }); 163 | 164 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 165 | { 166 | b.Navigation("AwayMatches"); 167 | 168 | b.Navigation("Coach"); 169 | 170 | b.Navigation("HomeMatches"); 171 | }); 172 | #pragma warning restore 612, 618 173 | } 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210620204824_AddingSPGetCoachName.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | namespace EntityFrameworkNet5.Data.Migrations 4 | { 5 | public partial class AddingSPGetCoachName : Migration 6 | { 7 | protected override void Up(MigrationBuilder migrationBuilder) 8 | { 9 | migrationBuilder.Sql(@"CREATE PROCEDURE sp_GetTeamCoach 10 | @teamId int 11 | AS 12 | BEGIN 13 | SELECT * from Coaches where TeamId = @teamid 14 | END"); 15 | } 16 | 17 | protected override void Down(MigrationBuilder migrationBuilder) 18 | { 19 | migrationBuilder.Sql(@"DROP PROCEDURE [dbo].[sp_CoachName]"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210620211644_AddDeleteTeamByIdSP.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using EntityFrameworkNet5.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace EntityFrameworkNet5.Data.Migrations 11 | { 12 | [DbContext(typeof(FootballLeageDbContext))] 13 | [Migration("20210620211644_AddDeleteTeamByIdSP")] 14 | partial class AddDeleteTeamByIdSP 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 21 | .HasAnnotation("ProductVersion", "5.0.7") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("int") 29 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 30 | 31 | b.Property("Name") 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("TeamId") 35 | .HasColumnType("int"); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.HasIndex("TeamId") 40 | .IsUnique() 41 | .HasFilter("[TeamId] IS NOT NULL"); 42 | 43 | b.ToTable("Coaches"); 44 | }); 45 | 46 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 47 | { 48 | b.Property("Id") 49 | .ValueGeneratedOnAdd() 50 | .HasColumnType("int") 51 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 52 | 53 | b.Property("Name") 54 | .HasColumnType("nvarchar(max)"); 55 | 56 | b.HasKey("Id"); 57 | 58 | b.ToTable("Leagues"); 59 | }); 60 | 61 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 62 | { 63 | b.Property("Id") 64 | .ValueGeneratedOnAdd() 65 | .HasColumnType("int") 66 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 67 | 68 | b.Property("AwayTeamId") 69 | .HasColumnType("int"); 70 | 71 | b.Property("Date") 72 | .HasColumnType("datetime2"); 73 | 74 | b.Property("HomeTeamId") 75 | .HasColumnType("int"); 76 | 77 | b.HasKey("Id"); 78 | 79 | b.HasIndex("AwayTeamId"); 80 | 81 | b.HasIndex("HomeTeamId"); 82 | 83 | b.ToTable("Matches"); 84 | }); 85 | 86 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 87 | { 88 | b.Property("Id") 89 | .ValueGeneratedOnAdd() 90 | .HasColumnType("int") 91 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 92 | 93 | b.Property("LeagueId") 94 | .HasColumnType("int"); 95 | 96 | b.Property("Name") 97 | .HasColumnType("nvarchar(max)"); 98 | 99 | b.HasKey("Id"); 100 | 101 | b.HasIndex("LeagueId"); 102 | 103 | b.ToTable("Teams"); 104 | }); 105 | 106 | modelBuilder.Entity("EntityFrameworkNet5.Domain.TeamsCoachesLeaguesView", b => 107 | { 108 | b.Property("CoachName") 109 | .HasColumnType("nvarchar(max)"); 110 | 111 | b.Property("LeagueName") 112 | .HasColumnType("nvarchar(max)"); 113 | 114 | b.Property("Name") 115 | .HasColumnType("nvarchar(max)"); 116 | 117 | b.ToView("TeamsCoachesLeagues"); 118 | }); 119 | 120 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 121 | { 122 | b.HasOne("EntityFrameworkNet5.Domain.Team", "Team") 123 | .WithOne("Coach") 124 | .HasForeignKey("EntityFrameworkNet5.Domain.Coach", "TeamId"); 125 | 126 | b.Navigation("Team"); 127 | }); 128 | 129 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 130 | { 131 | b.HasOne("EntityFrameworkNet5.Domain.Team", "AwayTeam") 132 | .WithMany("AwayMatches") 133 | .HasForeignKey("AwayTeamId") 134 | .OnDelete(DeleteBehavior.Restrict) 135 | .IsRequired(); 136 | 137 | b.HasOne("EntityFrameworkNet5.Domain.Team", "HomeTeam") 138 | .WithMany("HomeMatches") 139 | .HasForeignKey("HomeTeamId") 140 | .OnDelete(DeleteBehavior.Restrict) 141 | .IsRequired(); 142 | 143 | b.Navigation("AwayTeam"); 144 | 145 | b.Navigation("HomeTeam"); 146 | }); 147 | 148 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 149 | { 150 | b.HasOne("EntityFrameworkNet5.Domain.League", "League") 151 | .WithMany("Teams") 152 | .HasForeignKey("LeagueId") 153 | .OnDelete(DeleteBehavior.Cascade) 154 | .IsRequired(); 155 | 156 | b.Navigation("League"); 157 | }); 158 | 159 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 160 | { 161 | b.Navigation("Teams"); 162 | }); 163 | 164 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 165 | { 166 | b.Navigation("AwayMatches"); 167 | 168 | b.Navigation("Coach"); 169 | 170 | b.Navigation("HomeMatches"); 171 | }); 172 | #pragma warning restore 612, 618 173 | } 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210620211644_AddDeleteTeamByIdSP.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | namespace EntityFrameworkNet5.Data.Migrations 4 | { 5 | public partial class AddDeleteTeamByIdSP : Migration 6 | { 7 | protected override void Up(MigrationBuilder migrationBuilder) 8 | { 9 | migrationBuilder.Sql(@"CREATE PROCEDURE sp_DeleteTeamById 10 | @teamId int 11 | AS 12 | BEGIN 13 | Delete from Teams where Id = @teamId 14 | END"); 15 | } 16 | 17 | protected override void Down(MigrationBuilder migrationBuilder) 18 | { 19 | migrationBuilder.Sql(@"DROP PROCEDURE [dbo].[sp_DeleteTeamById]"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210620215933_AddedDefaultTeamsAndCoaches.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using EntityFrameworkNet5.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace EntityFrameworkNet5.Data.Migrations 11 | { 12 | [DbContext(typeof(FootballLeageDbContext))] 13 | [Migration("20210620215933_AddedDefaultTeamsAndCoaches")] 14 | partial class AddedDefaultTeamsAndCoaches 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 21 | .HasAnnotation("ProductVersion", "5.0.7") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("int") 29 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 30 | 31 | b.Property("Name") 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("TeamId") 35 | .HasColumnType("int"); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.HasIndex("TeamId") 40 | .IsUnique() 41 | .HasFilter("[TeamId] IS NOT NULL"); 42 | 43 | b.ToTable("Coaches"); 44 | 45 | b.HasData( 46 | new 47 | { 48 | Id = 20, 49 | Name = "Trevoir Williams", 50 | TeamId = 20 51 | }, 52 | new 53 | { 54 | Id = 21, 55 | Name = "Trevoir Williams - Sample 1", 56 | TeamId = 21 57 | }, 58 | new 59 | { 60 | Id = 22, 61 | Name = "Trevoir Williams - Sample 2", 62 | TeamId = 22 63 | }); 64 | }); 65 | 66 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 67 | { 68 | b.Property("Id") 69 | .ValueGeneratedOnAdd() 70 | .HasColumnType("int") 71 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 72 | 73 | b.Property("Name") 74 | .HasColumnType("nvarchar(max)"); 75 | 76 | b.HasKey("Id"); 77 | 78 | b.ToTable("Leagues"); 79 | 80 | b.HasData( 81 | new 82 | { 83 | Id = 20, 84 | Name = "Sample League" 85 | }); 86 | }); 87 | 88 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 89 | { 90 | b.Property("Id") 91 | .ValueGeneratedOnAdd() 92 | .HasColumnType("int") 93 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 94 | 95 | b.Property("AwayTeamId") 96 | .HasColumnType("int"); 97 | 98 | b.Property("Date") 99 | .HasColumnType("datetime2"); 100 | 101 | b.Property("HomeTeamId") 102 | .HasColumnType("int"); 103 | 104 | b.HasKey("Id"); 105 | 106 | b.HasIndex("AwayTeamId"); 107 | 108 | b.HasIndex("HomeTeamId"); 109 | 110 | b.ToTable("Matches"); 111 | }); 112 | 113 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 114 | { 115 | b.Property("Id") 116 | .ValueGeneratedOnAdd() 117 | .HasColumnType("int") 118 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 119 | 120 | b.Property("LeagueId") 121 | .HasColumnType("int"); 122 | 123 | b.Property("Name") 124 | .HasColumnType("nvarchar(max)"); 125 | 126 | b.HasKey("Id"); 127 | 128 | b.HasIndex("LeagueId"); 129 | 130 | b.ToTable("Teams"); 131 | 132 | b.HasData( 133 | new 134 | { 135 | Id = 20, 136 | LeagueId = 20, 137 | Name = "Trevoir Williams - Sample Team" 138 | }, 139 | new 140 | { 141 | Id = 21, 142 | LeagueId = 20, 143 | Name = "Trevoir Williams - Sample Team" 144 | }, 145 | new 146 | { 147 | Id = 22, 148 | LeagueId = 20, 149 | Name = "Trevoir Williams - Sample Team" 150 | }); 151 | }); 152 | 153 | modelBuilder.Entity("EntityFrameworkNet5.Domain.TeamsCoachesLeaguesView", b => 154 | { 155 | b.Property("CoachName") 156 | .HasColumnType("nvarchar(max)"); 157 | 158 | b.Property("LeagueName") 159 | .HasColumnType("nvarchar(max)"); 160 | 161 | b.Property("Name") 162 | .HasColumnType("nvarchar(max)"); 163 | 164 | b.ToView("TeamsCoachesLeagues"); 165 | }); 166 | 167 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 168 | { 169 | b.HasOne("EntityFrameworkNet5.Domain.Team", "Team") 170 | .WithOne("Coach") 171 | .HasForeignKey("EntityFrameworkNet5.Domain.Coach", "TeamId"); 172 | 173 | b.Navigation("Team"); 174 | }); 175 | 176 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 177 | { 178 | b.HasOne("EntityFrameworkNet5.Domain.Team", "AwayTeam") 179 | .WithMany("AwayMatches") 180 | .HasForeignKey("AwayTeamId") 181 | .OnDelete(DeleteBehavior.Restrict) 182 | .IsRequired(); 183 | 184 | b.HasOne("EntityFrameworkNet5.Domain.Team", "HomeTeam") 185 | .WithMany("HomeMatches") 186 | .HasForeignKey("HomeTeamId") 187 | .OnDelete(DeleteBehavior.Restrict) 188 | .IsRequired(); 189 | 190 | b.Navigation("AwayTeam"); 191 | 192 | b.Navigation("HomeTeam"); 193 | }); 194 | 195 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 196 | { 197 | b.HasOne("EntityFrameworkNet5.Domain.League", "League") 198 | .WithMany("Teams") 199 | .HasForeignKey("LeagueId") 200 | .OnDelete(DeleteBehavior.Cascade) 201 | .IsRequired(); 202 | 203 | b.Navigation("League"); 204 | }); 205 | 206 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 207 | { 208 | b.Navigation("Teams"); 209 | }); 210 | 211 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 212 | { 213 | b.Navigation("AwayMatches"); 214 | 215 | b.Navigation("Coach"); 216 | 217 | b.Navigation("HomeMatches"); 218 | }); 219 | #pragma warning restore 612, 618 220 | } 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210620215933_AddedDefaultTeamsAndCoaches.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | namespace EntityFrameworkNet5.Data.Migrations 4 | { 5 | public partial class AddedDefaultTeamsAndCoaches : Migration 6 | { 7 | protected override void Up(MigrationBuilder migrationBuilder) 8 | { 9 | migrationBuilder.InsertData( 10 | table: "Leagues", 11 | columns: new[] { "Id", "Name" }, 12 | values: new object[] { 20, "Sample League" }); 13 | 14 | migrationBuilder.InsertData( 15 | table: "Teams", 16 | columns: new[] { "Id", "LeagueId", "Name" }, 17 | values: new object[] { 20, 20, "Trevoir Williams - Sample Team" }); 18 | 19 | migrationBuilder.InsertData( 20 | table: "Teams", 21 | columns: new[] { "Id", "LeagueId", "Name" }, 22 | values: new object[] { 21, 20, "Trevoir Williams - Sample Team" }); 23 | 24 | migrationBuilder.InsertData( 25 | table: "Teams", 26 | columns: new[] { "Id", "LeagueId", "Name" }, 27 | values: new object[] { 22, 20, "Trevoir Williams - Sample Team" }); 28 | 29 | migrationBuilder.InsertData( 30 | table: "Coaches", 31 | columns: new[] { "Id", "Name", "TeamId" }, 32 | values: new object[] { 20, "Trevoir Williams", 20 }); 33 | 34 | migrationBuilder.InsertData( 35 | table: "Coaches", 36 | columns: new[] { "Id", "Name", "TeamId" }, 37 | values: new object[] { 21, "Trevoir Williams - Sample 1", 21 }); 38 | 39 | migrationBuilder.InsertData( 40 | table: "Coaches", 41 | columns: new[] { "Id", "Name", "TeamId" }, 42 | values: new object[] { 22, "Trevoir Williams - Sample 2", 22 }); 43 | } 44 | 45 | protected override void Down(MigrationBuilder migrationBuilder) 46 | { 47 | migrationBuilder.DeleteData( 48 | table: "Coaches", 49 | keyColumn: "Id", 50 | keyValue: 20); 51 | 52 | migrationBuilder.DeleteData( 53 | table: "Coaches", 54 | keyColumn: "Id", 55 | keyValue: 21); 56 | 57 | migrationBuilder.DeleteData( 58 | table: "Coaches", 59 | keyColumn: "Id", 60 | keyValue: 22); 61 | 62 | migrationBuilder.DeleteData( 63 | table: "Teams", 64 | keyColumn: "Id", 65 | keyValue: 20); 66 | 67 | migrationBuilder.DeleteData( 68 | table: "Teams", 69 | keyColumn: "Id", 70 | keyValue: 21); 71 | 72 | migrationBuilder.DeleteData( 73 | table: "Teams", 74 | keyColumn: "Id", 75 | keyValue: 22); 76 | 77 | migrationBuilder.DeleteData( 78 | table: "Leagues", 79 | keyColumn: "Id", 80 | keyValue: 20); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210622010052_AddedAuditFields.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using EntityFrameworkNet5.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace EntityFrameworkNet5.Data.Migrations 11 | { 12 | [DbContext(typeof(FootballLeageDbContext))] 13 | [Migration("20210622010052_AddedAuditFields")] 14 | partial class AddedAuditFields 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 21 | .HasAnnotation("ProductVersion", "5.0.7") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("int") 29 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 30 | 31 | b.Property("CreatedBy") 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("CreatedDate") 35 | .HasColumnType("datetime2"); 36 | 37 | b.Property("ModifiedBy") 38 | .HasColumnType("nvarchar(max)"); 39 | 40 | b.Property("ModifiedDate") 41 | .HasColumnType("datetime2"); 42 | 43 | b.Property("Name") 44 | .HasColumnType("nvarchar(max)"); 45 | 46 | b.Property("TeamId") 47 | .HasColumnType("int"); 48 | 49 | b.HasKey("Id"); 50 | 51 | b.HasIndex("TeamId") 52 | .IsUnique() 53 | .HasFilter("[TeamId] IS NOT NULL"); 54 | 55 | b.ToTable("Coaches"); 56 | 57 | b.HasData( 58 | new 59 | { 60 | Id = 20, 61 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 62 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 63 | Name = "Trevoir Williams", 64 | TeamId = 20 65 | }, 66 | new 67 | { 68 | Id = 21, 69 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 70 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 71 | Name = "Trevoir Williams - Sample 1", 72 | TeamId = 21 73 | }, 74 | new 75 | { 76 | Id = 22, 77 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 78 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 79 | Name = "Trevoir Williams - Sample 2", 80 | TeamId = 22 81 | }); 82 | }); 83 | 84 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 85 | { 86 | b.Property("Id") 87 | .ValueGeneratedOnAdd() 88 | .HasColumnType("int") 89 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 90 | 91 | b.Property("CreatedBy") 92 | .HasColumnType("nvarchar(max)"); 93 | 94 | b.Property("CreatedDate") 95 | .HasColumnType("datetime2"); 96 | 97 | b.Property("ModifiedBy") 98 | .HasColumnType("nvarchar(max)"); 99 | 100 | b.Property("ModifiedDate") 101 | .HasColumnType("datetime2"); 102 | 103 | b.Property("Name") 104 | .HasColumnType("nvarchar(max)"); 105 | 106 | b.HasKey("Id"); 107 | 108 | b.ToTable("Leagues"); 109 | 110 | b.HasData( 111 | new 112 | { 113 | Id = 20, 114 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 115 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 116 | Name = "Sample League" 117 | }); 118 | }); 119 | 120 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 121 | { 122 | b.Property("Id") 123 | .ValueGeneratedOnAdd() 124 | .HasColumnType("int") 125 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 126 | 127 | b.Property("AwayTeamId") 128 | .HasColumnType("int"); 129 | 130 | b.Property("CreatedBy") 131 | .HasColumnType("nvarchar(max)"); 132 | 133 | b.Property("CreatedDate") 134 | .HasColumnType("datetime2"); 135 | 136 | b.Property("Date") 137 | .HasColumnType("datetime2"); 138 | 139 | b.Property("HomeTeamId") 140 | .HasColumnType("int"); 141 | 142 | b.Property("ModifiedBy") 143 | .HasColumnType("nvarchar(max)"); 144 | 145 | b.Property("ModifiedDate") 146 | .HasColumnType("datetime2"); 147 | 148 | b.HasKey("Id"); 149 | 150 | b.HasIndex("AwayTeamId"); 151 | 152 | b.HasIndex("HomeTeamId"); 153 | 154 | b.ToTable("Matches"); 155 | }); 156 | 157 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 158 | { 159 | b.Property("Id") 160 | .ValueGeneratedOnAdd() 161 | .HasColumnType("int") 162 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 163 | 164 | b.Property("CreatedBy") 165 | .HasColumnType("nvarchar(max)"); 166 | 167 | b.Property("CreatedDate") 168 | .HasColumnType("datetime2"); 169 | 170 | b.Property("LeagueId") 171 | .HasColumnType("int"); 172 | 173 | b.Property("ModifiedBy") 174 | .HasColumnType("nvarchar(max)"); 175 | 176 | b.Property("ModifiedDate") 177 | .HasColumnType("datetime2"); 178 | 179 | b.Property("Name") 180 | .HasColumnType("nvarchar(max)"); 181 | 182 | b.HasKey("Id"); 183 | 184 | b.HasIndex("LeagueId"); 185 | 186 | b.ToTable("Teams"); 187 | 188 | b.HasData( 189 | new 190 | { 191 | Id = 20, 192 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 193 | LeagueId = 20, 194 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 195 | Name = "Trevoir Williams - Sample Team" 196 | }, 197 | new 198 | { 199 | Id = 21, 200 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 201 | LeagueId = 20, 202 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 203 | Name = "Trevoir Williams - Sample Team" 204 | }, 205 | new 206 | { 207 | Id = 22, 208 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 209 | LeagueId = 20, 210 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 211 | Name = "Trevoir Williams - Sample Team" 212 | }); 213 | }); 214 | 215 | modelBuilder.Entity("EntityFrameworkNet5.Domain.TeamsCoachesLeaguesView", b => 216 | { 217 | b.Property("CoachName") 218 | .HasColumnType("nvarchar(max)"); 219 | 220 | b.Property("LeagueName") 221 | .HasColumnType("nvarchar(max)"); 222 | 223 | b.Property("Name") 224 | .HasColumnType("nvarchar(max)"); 225 | 226 | b.ToView("TeamsCoachesLeagues"); 227 | }); 228 | 229 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 230 | { 231 | b.HasOne("EntityFrameworkNet5.Domain.Team", "Team") 232 | .WithOne("Coach") 233 | .HasForeignKey("EntityFrameworkNet5.Domain.Coach", "TeamId"); 234 | 235 | b.Navigation("Team"); 236 | }); 237 | 238 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 239 | { 240 | b.HasOne("EntityFrameworkNet5.Domain.Team", "AwayTeam") 241 | .WithMany("AwayMatches") 242 | .HasForeignKey("AwayTeamId") 243 | .OnDelete(DeleteBehavior.Restrict) 244 | .IsRequired(); 245 | 246 | b.HasOne("EntityFrameworkNet5.Domain.Team", "HomeTeam") 247 | .WithMany("HomeMatches") 248 | .HasForeignKey("HomeTeamId") 249 | .OnDelete(DeleteBehavior.Restrict) 250 | .IsRequired(); 251 | 252 | b.Navigation("AwayTeam"); 253 | 254 | b.Navigation("HomeTeam"); 255 | }); 256 | 257 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 258 | { 259 | b.HasOne("EntityFrameworkNet5.Domain.League", "League") 260 | .WithMany("Teams") 261 | .HasForeignKey("LeagueId") 262 | .OnDelete(DeleteBehavior.Cascade) 263 | .IsRequired(); 264 | 265 | b.Navigation("League"); 266 | }); 267 | 268 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 269 | { 270 | b.Navigation("Teams"); 271 | }); 272 | 273 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 274 | { 275 | b.Navigation("AwayMatches"); 276 | 277 | b.Navigation("Coach"); 278 | 279 | b.Navigation("HomeMatches"); 280 | }); 281 | #pragma warning restore 612, 618 282 | } 283 | } 284 | } 285 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210622010052_AddedAuditFields.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | namespace EntityFrameworkNet5.Data.Migrations 5 | { 6 | public partial class AddedAuditFields : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.AddColumn( 11 | name: "CreatedBy", 12 | table: "Teams", 13 | type: "nvarchar(max)", 14 | nullable: true); 15 | 16 | migrationBuilder.AddColumn( 17 | name: "CreatedDate", 18 | table: "Teams", 19 | type: "datetime2", 20 | nullable: false, 21 | defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); 22 | 23 | migrationBuilder.AddColumn( 24 | name: "ModifiedBy", 25 | table: "Teams", 26 | type: "nvarchar(max)", 27 | nullable: true); 28 | 29 | migrationBuilder.AddColumn( 30 | name: "ModifiedDate", 31 | table: "Teams", 32 | type: "datetime2", 33 | nullable: false, 34 | defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); 35 | 36 | migrationBuilder.AddColumn( 37 | name: "CreatedBy", 38 | table: "Matches", 39 | type: "nvarchar(max)", 40 | nullable: true); 41 | 42 | migrationBuilder.AddColumn( 43 | name: "CreatedDate", 44 | table: "Matches", 45 | type: "datetime2", 46 | nullable: false, 47 | defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); 48 | 49 | migrationBuilder.AddColumn( 50 | name: "ModifiedBy", 51 | table: "Matches", 52 | type: "nvarchar(max)", 53 | nullable: true); 54 | 55 | migrationBuilder.AddColumn( 56 | name: "ModifiedDate", 57 | table: "Matches", 58 | type: "datetime2", 59 | nullable: false, 60 | defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); 61 | 62 | migrationBuilder.AddColumn( 63 | name: "CreatedBy", 64 | table: "Leagues", 65 | type: "nvarchar(max)", 66 | nullable: true); 67 | 68 | migrationBuilder.AddColumn( 69 | name: "CreatedDate", 70 | table: "Leagues", 71 | type: "datetime2", 72 | nullable: false, 73 | defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); 74 | 75 | migrationBuilder.AddColumn( 76 | name: "ModifiedBy", 77 | table: "Leagues", 78 | type: "nvarchar(max)", 79 | nullable: true); 80 | 81 | migrationBuilder.AddColumn( 82 | name: "ModifiedDate", 83 | table: "Leagues", 84 | type: "datetime2", 85 | nullable: false, 86 | defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); 87 | 88 | migrationBuilder.AddColumn( 89 | name: "CreatedBy", 90 | table: "Coaches", 91 | type: "nvarchar(max)", 92 | nullable: true); 93 | 94 | migrationBuilder.AddColumn( 95 | name: "CreatedDate", 96 | table: "Coaches", 97 | type: "datetime2", 98 | nullable: false, 99 | defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); 100 | 101 | migrationBuilder.AddColumn( 102 | name: "ModifiedBy", 103 | table: "Coaches", 104 | type: "nvarchar(max)", 105 | nullable: true); 106 | 107 | migrationBuilder.AddColumn( 108 | name: "ModifiedDate", 109 | table: "Coaches", 110 | type: "datetime2", 111 | nullable: false, 112 | defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); 113 | } 114 | 115 | protected override void Down(MigrationBuilder migrationBuilder) 116 | { 117 | migrationBuilder.DropColumn( 118 | name: "CreatedBy", 119 | table: "Teams"); 120 | 121 | migrationBuilder.DropColumn( 122 | name: "CreatedDate", 123 | table: "Teams"); 124 | 125 | migrationBuilder.DropColumn( 126 | name: "ModifiedBy", 127 | table: "Teams"); 128 | 129 | migrationBuilder.DropColumn( 130 | name: "ModifiedDate", 131 | table: "Teams"); 132 | 133 | migrationBuilder.DropColumn( 134 | name: "CreatedBy", 135 | table: "Matches"); 136 | 137 | migrationBuilder.DropColumn( 138 | name: "CreatedDate", 139 | table: "Matches"); 140 | 141 | migrationBuilder.DropColumn( 142 | name: "ModifiedBy", 143 | table: "Matches"); 144 | 145 | migrationBuilder.DropColumn( 146 | name: "ModifiedDate", 147 | table: "Matches"); 148 | 149 | migrationBuilder.DropColumn( 150 | name: "CreatedBy", 151 | table: "Leagues"); 152 | 153 | migrationBuilder.DropColumn( 154 | name: "CreatedDate", 155 | table: "Leagues"); 156 | 157 | migrationBuilder.DropColumn( 158 | name: "ModifiedBy", 159 | table: "Leagues"); 160 | 161 | migrationBuilder.DropColumn( 162 | name: "ModifiedDate", 163 | table: "Leagues"); 164 | 165 | migrationBuilder.DropColumn( 166 | name: "CreatedBy", 167 | table: "Coaches"); 168 | 169 | migrationBuilder.DropColumn( 170 | name: "CreatedDate", 171 | table: "Coaches"); 172 | 173 | migrationBuilder.DropColumn( 174 | name: "ModifiedBy", 175 | table: "Coaches"); 176 | 177 | migrationBuilder.DropColumn( 178 | name: "ModifiedDate", 179 | table: "Coaches"); 180 | } 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210622232509_AddedValidations.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using EntityFrameworkNet5.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace EntityFrameworkNet5.Data.Migrations 11 | { 12 | [DbContext(typeof(FootballLeageDbContext))] 13 | [Migration("20210622232509_AddedValidations")] 14 | partial class AddedValidations 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 21 | .HasAnnotation("ProductVersion", "5.0.7") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("int") 29 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 30 | 31 | b.Property("CreatedBy") 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("CreatedDate") 35 | .HasColumnType("datetime2"); 36 | 37 | b.Property("ModifiedBy") 38 | .HasColumnType("nvarchar(max)"); 39 | 40 | b.Property("ModifiedDate") 41 | .HasColumnType("datetime2"); 42 | 43 | b.Property("Name") 44 | .HasMaxLength(50) 45 | .HasColumnType("nvarchar(50)"); 46 | 47 | b.Property("TeamId") 48 | .HasColumnType("int"); 49 | 50 | b.HasKey("Id"); 51 | 52 | b.HasIndex("TeamId") 53 | .IsUnique() 54 | .HasFilter("[TeamId] IS NOT NULL"); 55 | 56 | b.HasIndex("Name", "TeamId") 57 | .IsUnique() 58 | .HasFilter("[Name] IS NOT NULL AND [TeamId] IS NOT NULL"); 59 | 60 | b.ToTable("Coaches"); 61 | 62 | b.HasData( 63 | new 64 | { 65 | Id = 20, 66 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 67 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 68 | Name = "Trevoir Williams", 69 | TeamId = 20 70 | }, 71 | new 72 | { 73 | Id = 21, 74 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 75 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 76 | Name = "Trevoir Williams - Sample 1", 77 | TeamId = 21 78 | }, 79 | new 80 | { 81 | Id = 22, 82 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 83 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 84 | Name = "Trevoir Williams - Sample 2", 85 | TeamId = 22 86 | }); 87 | }); 88 | 89 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 90 | { 91 | b.Property("Id") 92 | .ValueGeneratedOnAdd() 93 | .HasColumnType("int") 94 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 95 | 96 | b.Property("CreatedBy") 97 | .HasColumnType("nvarchar(max)"); 98 | 99 | b.Property("CreatedDate") 100 | .HasColumnType("datetime2"); 101 | 102 | b.Property("ModifiedBy") 103 | .HasColumnType("nvarchar(max)"); 104 | 105 | b.Property("ModifiedDate") 106 | .HasColumnType("datetime2"); 107 | 108 | b.Property("Name") 109 | .HasMaxLength(50) 110 | .HasColumnType("nvarchar(50)"); 111 | 112 | b.HasKey("Id"); 113 | 114 | b.HasIndex("Name"); 115 | 116 | b.ToTable("Leagues"); 117 | 118 | b.HasData( 119 | new 120 | { 121 | Id = 20, 122 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 123 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 124 | Name = "Sample League" 125 | }); 126 | }); 127 | 128 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 129 | { 130 | b.Property("Id") 131 | .ValueGeneratedOnAdd() 132 | .HasColumnType("int") 133 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 134 | 135 | b.Property("AwayTeamId") 136 | .HasColumnType("int"); 137 | 138 | b.Property("CreatedBy") 139 | .HasColumnType("nvarchar(max)"); 140 | 141 | b.Property("CreatedDate") 142 | .HasColumnType("datetime2"); 143 | 144 | b.Property("Date") 145 | .HasColumnType("datetime2"); 146 | 147 | b.Property("HomeTeamId") 148 | .HasColumnType("int"); 149 | 150 | b.Property("ModifiedBy") 151 | .HasColumnType("nvarchar(max)"); 152 | 153 | b.Property("ModifiedDate") 154 | .HasColumnType("datetime2"); 155 | 156 | b.HasKey("Id"); 157 | 158 | b.HasIndex("AwayTeamId"); 159 | 160 | b.HasIndex("HomeTeamId"); 161 | 162 | b.ToTable("Matches"); 163 | }); 164 | 165 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 166 | { 167 | b.Property("Id") 168 | .ValueGeneratedOnAdd() 169 | .HasColumnType("int") 170 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 171 | 172 | b.Property("CreatedBy") 173 | .HasColumnType("nvarchar(max)"); 174 | 175 | b.Property("CreatedDate") 176 | .HasColumnType("datetime2"); 177 | 178 | b.Property("LeagueId") 179 | .HasColumnType("int"); 180 | 181 | b.Property("ModifiedBy") 182 | .HasColumnType("nvarchar(max)"); 183 | 184 | b.Property("ModifiedDate") 185 | .HasColumnType("datetime2"); 186 | 187 | b.Property("Name") 188 | .HasMaxLength(50) 189 | .HasColumnType("nvarchar(50)"); 190 | 191 | b.HasKey("Id"); 192 | 193 | b.HasIndex("LeagueId"); 194 | 195 | b.HasIndex("Name") 196 | .IsUnique() 197 | .HasFilter("[Name] IS NOT NULL"); 198 | 199 | b.ToTable("Teams"); 200 | 201 | b.HasData( 202 | new 203 | { 204 | Id = 20, 205 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 206 | LeagueId = 20, 207 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 208 | Name = "Trevoir Williams - Sample Team" 209 | }, 210 | new 211 | { 212 | Id = 21, 213 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 214 | LeagueId = 20, 215 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 216 | Name = "Trevoir Williams - Sample Team" 217 | }, 218 | new 219 | { 220 | Id = 22, 221 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 222 | LeagueId = 20, 223 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 224 | Name = "Trevoir Williams - Sample Team" 225 | }); 226 | }); 227 | 228 | modelBuilder.Entity("EntityFrameworkNet5.Domain.TeamsCoachesLeaguesView", b => 229 | { 230 | b.Property("CoachName") 231 | .HasColumnType("nvarchar(max)"); 232 | 233 | b.Property("LeagueName") 234 | .HasColumnType("nvarchar(max)"); 235 | 236 | b.Property("Name") 237 | .HasColumnType("nvarchar(max)"); 238 | 239 | b.ToView("TeamsCoachesLeagues"); 240 | }); 241 | 242 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 243 | { 244 | b.HasOne("EntityFrameworkNet5.Domain.Team", "Team") 245 | .WithOne("Coach") 246 | .HasForeignKey("EntityFrameworkNet5.Domain.Coach", "TeamId"); 247 | 248 | b.Navigation("Team"); 249 | }); 250 | 251 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 252 | { 253 | b.HasOne("EntityFrameworkNet5.Domain.Team", "AwayTeam") 254 | .WithMany("AwayMatches") 255 | .HasForeignKey("AwayTeamId") 256 | .OnDelete(DeleteBehavior.Restrict) 257 | .IsRequired(); 258 | 259 | b.HasOne("EntityFrameworkNet5.Domain.Team", "HomeTeam") 260 | .WithMany("HomeMatches") 261 | .HasForeignKey("HomeTeamId") 262 | .OnDelete(DeleteBehavior.Restrict) 263 | .IsRequired(); 264 | 265 | b.Navigation("AwayTeam"); 266 | 267 | b.Navigation("HomeTeam"); 268 | }); 269 | 270 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 271 | { 272 | b.HasOne("EntityFrameworkNet5.Domain.League", "League") 273 | .WithMany("Teams") 274 | .HasForeignKey("LeagueId") 275 | .OnDelete(DeleteBehavior.Cascade) 276 | .IsRequired(); 277 | 278 | b.Navigation("League"); 279 | }); 280 | 281 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 282 | { 283 | b.Navigation("Teams"); 284 | }); 285 | 286 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 287 | { 288 | b.Navigation("AwayMatches"); 289 | 290 | b.Navigation("Coach"); 291 | 292 | b.Navigation("HomeMatches"); 293 | }); 294 | #pragma warning restore 612, 618 295 | } 296 | } 297 | } 298 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/20210622232509_AddedValidations.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | namespace EntityFrameworkNet5.Data.Migrations 4 | { 5 | public partial class AddedValidations : Migration 6 | { 7 | protected override void Up(MigrationBuilder migrationBuilder) 8 | { 9 | migrationBuilder.AlterColumn( 10 | name: "Name", 11 | table: "Teams", 12 | type: "nvarchar(50)", 13 | maxLength: 50, 14 | nullable: true, 15 | oldClrType: typeof(string), 16 | oldType: "nvarchar(max)", 17 | oldNullable: true); 18 | 19 | migrationBuilder.AlterColumn( 20 | name: "Name", 21 | table: "Leagues", 22 | type: "nvarchar(50)", 23 | maxLength: 50, 24 | nullable: true, 25 | oldClrType: typeof(string), 26 | oldType: "nvarchar(max)", 27 | oldNullable: true); 28 | 29 | migrationBuilder.AlterColumn( 30 | name: "Name", 31 | table: "Coaches", 32 | type: "nvarchar(50)", 33 | maxLength: 50, 34 | nullable: true, 35 | oldClrType: typeof(string), 36 | oldType: "nvarchar(max)", 37 | oldNullable: true); 38 | 39 | migrationBuilder.CreateIndex( 40 | name: "IX_Teams_Name", 41 | table: "Teams", 42 | column: "Name", 43 | unique: true, 44 | filter: "[Name] IS NOT NULL"); 45 | 46 | migrationBuilder.CreateIndex( 47 | name: "IX_Leagues_Name", 48 | table: "Leagues", 49 | column: "Name"); 50 | 51 | migrationBuilder.CreateIndex( 52 | name: "IX_Coaches_Name_TeamId", 53 | table: "Coaches", 54 | columns: new[] { "Name", "TeamId" }, 55 | unique: true, 56 | filter: "[Name] IS NOT NULL AND [TeamId] IS NOT NULL"); 57 | } 58 | 59 | protected override void Down(MigrationBuilder migrationBuilder) 60 | { 61 | migrationBuilder.DropIndex( 62 | name: "IX_Teams_Name", 63 | table: "Teams"); 64 | 65 | migrationBuilder.DropIndex( 66 | name: "IX_Leagues_Name", 67 | table: "Leagues"); 68 | 69 | migrationBuilder.DropIndex( 70 | name: "IX_Coaches_Name_TeamId", 71 | table: "Coaches"); 72 | 73 | migrationBuilder.AlterColumn( 74 | name: "Name", 75 | table: "Teams", 76 | type: "nvarchar(max)", 77 | nullable: true, 78 | oldClrType: typeof(string), 79 | oldType: "nvarchar(50)", 80 | oldMaxLength: 50, 81 | oldNullable: true); 82 | 83 | migrationBuilder.AlterColumn( 84 | name: "Name", 85 | table: "Leagues", 86 | type: "nvarchar(max)", 87 | nullable: true, 88 | oldClrType: typeof(string), 89 | oldType: "nvarchar(50)", 90 | oldMaxLength: 50, 91 | oldNullable: true); 92 | 93 | migrationBuilder.AlterColumn( 94 | name: "Name", 95 | table: "Coaches", 96 | type: "nvarchar(max)", 97 | nullable: true, 98 | oldClrType: typeof(string), 99 | oldType: "nvarchar(50)", 100 | oldMaxLength: 50, 101 | oldNullable: true); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Data/Migrations/FootballLeageDbContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using EntityFrameworkNet5.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | namespace EntityFrameworkNet5.Data.Migrations 10 | { 11 | [DbContext(typeof(FootballLeageDbContext))] 12 | partial class FootballLeageDbContextModelSnapshot : ModelSnapshot 13 | { 14 | protected override void BuildModel(ModelBuilder modelBuilder) 15 | { 16 | #pragma warning disable 612, 618 17 | modelBuilder 18 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 19 | .HasAnnotation("ProductVersion", "5.0.7") 20 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 21 | 22 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 23 | { 24 | b.Property("Id") 25 | .ValueGeneratedOnAdd() 26 | .HasColumnType("int") 27 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 28 | 29 | b.Property("CreatedBy") 30 | .HasColumnType("nvarchar(max)"); 31 | 32 | b.Property("CreatedDate") 33 | .HasColumnType("datetime2"); 34 | 35 | b.Property("ModifiedBy") 36 | .HasColumnType("nvarchar(max)"); 37 | 38 | b.Property("ModifiedDate") 39 | .HasColumnType("datetime2"); 40 | 41 | b.Property("Name") 42 | .HasMaxLength(50) 43 | .HasColumnType("nvarchar(50)"); 44 | 45 | b.Property("TeamId") 46 | .HasColumnType("int"); 47 | 48 | b.HasKey("Id"); 49 | 50 | b.HasIndex("TeamId") 51 | .IsUnique() 52 | .HasFilter("[TeamId] IS NOT NULL"); 53 | 54 | b.HasIndex("Name", "TeamId") 55 | .IsUnique() 56 | .HasFilter("[Name] IS NOT NULL AND [TeamId] IS NOT NULL"); 57 | 58 | b.ToTable("Coaches"); 59 | 60 | b.HasData( 61 | new 62 | { 63 | Id = 20, 64 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 65 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 66 | Name = "Trevoir Williams", 67 | TeamId = 20 68 | }, 69 | new 70 | { 71 | Id = 21, 72 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 73 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 74 | Name = "Trevoir Williams - Sample 1", 75 | TeamId = 21 76 | }, 77 | new 78 | { 79 | Id = 22, 80 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 81 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 82 | Name = "Trevoir Williams - Sample 2", 83 | TeamId = 22 84 | }); 85 | }); 86 | 87 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 88 | { 89 | b.Property("Id") 90 | .ValueGeneratedOnAdd() 91 | .HasColumnType("int") 92 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 93 | 94 | b.Property("CreatedBy") 95 | .HasColumnType("nvarchar(max)"); 96 | 97 | b.Property("CreatedDate") 98 | .HasColumnType("datetime2"); 99 | 100 | b.Property("ModifiedBy") 101 | .HasColumnType("nvarchar(max)"); 102 | 103 | b.Property("ModifiedDate") 104 | .HasColumnType("datetime2"); 105 | 106 | b.Property("Name") 107 | .HasMaxLength(50) 108 | .HasColumnType("nvarchar(50)"); 109 | 110 | b.HasKey("Id"); 111 | 112 | b.HasIndex("Name"); 113 | 114 | b.ToTable("Leagues"); 115 | 116 | b.HasData( 117 | new 118 | { 119 | Id = 20, 120 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 121 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 122 | Name = "Sample League" 123 | }); 124 | }); 125 | 126 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 127 | { 128 | b.Property("Id") 129 | .ValueGeneratedOnAdd() 130 | .HasColumnType("int") 131 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 132 | 133 | b.Property("AwayTeamId") 134 | .HasColumnType("int"); 135 | 136 | b.Property("CreatedBy") 137 | .HasColumnType("nvarchar(max)"); 138 | 139 | b.Property("CreatedDate") 140 | .HasColumnType("datetime2"); 141 | 142 | b.Property("Date") 143 | .HasColumnType("datetime2"); 144 | 145 | b.Property("HomeTeamId") 146 | .HasColumnType("int"); 147 | 148 | b.Property("ModifiedBy") 149 | .HasColumnType("nvarchar(max)"); 150 | 151 | b.Property("ModifiedDate") 152 | .HasColumnType("datetime2"); 153 | 154 | b.HasKey("Id"); 155 | 156 | b.HasIndex("AwayTeamId"); 157 | 158 | b.HasIndex("HomeTeamId"); 159 | 160 | b.ToTable("Matches"); 161 | }); 162 | 163 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 164 | { 165 | b.Property("Id") 166 | .ValueGeneratedOnAdd() 167 | .HasColumnType("int") 168 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 169 | 170 | b.Property("CreatedBy") 171 | .HasColumnType("nvarchar(max)"); 172 | 173 | b.Property("CreatedDate") 174 | .HasColumnType("datetime2"); 175 | 176 | b.Property("LeagueId") 177 | .HasColumnType("int"); 178 | 179 | b.Property("ModifiedBy") 180 | .HasColumnType("nvarchar(max)"); 181 | 182 | b.Property("ModifiedDate") 183 | .HasColumnType("datetime2"); 184 | 185 | b.Property("Name") 186 | .HasMaxLength(50) 187 | .HasColumnType("nvarchar(50)"); 188 | 189 | b.HasKey("Id"); 190 | 191 | b.HasIndex("LeagueId"); 192 | 193 | b.HasIndex("Name") 194 | .IsUnique() 195 | .HasFilter("[Name] IS NOT NULL"); 196 | 197 | b.ToTable("Teams"); 198 | 199 | b.HasData( 200 | new 201 | { 202 | Id = 20, 203 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 204 | LeagueId = 20, 205 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 206 | Name = "Trevoir Williams - Sample Team" 207 | }, 208 | new 209 | { 210 | Id = 21, 211 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 212 | LeagueId = 20, 213 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 214 | Name = "Trevoir Williams - Sample Team" 215 | }, 216 | new 217 | { 218 | Id = 22, 219 | CreatedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 220 | LeagueId = 20, 221 | ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 222 | Name = "Trevoir Williams - Sample Team" 223 | }); 224 | }); 225 | 226 | modelBuilder.Entity("EntityFrameworkNet5.Domain.TeamsCoachesLeaguesView", b => 227 | { 228 | b.Property("CoachName") 229 | .HasColumnType("nvarchar(max)"); 230 | 231 | b.Property("LeagueName") 232 | .HasColumnType("nvarchar(max)"); 233 | 234 | b.Property("Name") 235 | .HasColumnType("nvarchar(max)"); 236 | 237 | b.ToView("TeamsCoachesLeagues"); 238 | }); 239 | 240 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Coach", b => 241 | { 242 | b.HasOne("EntityFrameworkNet5.Domain.Team", "Team") 243 | .WithOne("Coach") 244 | .HasForeignKey("EntityFrameworkNet5.Domain.Coach", "TeamId"); 245 | 246 | b.Navigation("Team"); 247 | }); 248 | 249 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Match", b => 250 | { 251 | b.HasOne("EntityFrameworkNet5.Domain.Team", "AwayTeam") 252 | .WithMany("AwayMatches") 253 | .HasForeignKey("AwayTeamId") 254 | .OnDelete(DeleteBehavior.Restrict) 255 | .IsRequired(); 256 | 257 | b.HasOne("EntityFrameworkNet5.Domain.Team", "HomeTeam") 258 | .WithMany("HomeMatches") 259 | .HasForeignKey("HomeTeamId") 260 | .OnDelete(DeleteBehavior.Restrict) 261 | .IsRequired(); 262 | 263 | b.Navigation("AwayTeam"); 264 | 265 | b.Navigation("HomeTeam"); 266 | }); 267 | 268 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 269 | { 270 | b.HasOne("EntityFrameworkNet5.Domain.League", "League") 271 | .WithMany("Teams") 272 | .HasForeignKey("LeagueId") 273 | .OnDelete(DeleteBehavior.Cascade) 274 | .IsRequired(); 275 | 276 | b.Navigation("League"); 277 | }); 278 | 279 | modelBuilder.Entity("EntityFrameworkNet5.Domain.League", b => 280 | { 281 | b.Navigation("Teams"); 282 | }); 283 | 284 | modelBuilder.Entity("EntityFrameworkNet5.Domain.Team", b => 285 | { 286 | b.Navigation("AwayMatches"); 287 | 288 | b.Navigation("Coach"); 289 | 290 | b.Navigation("HomeMatches"); 291 | }); 292 | #pragma warning restore 612, 618 293 | } 294 | } 295 | } 296 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Domain/Coach.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkNet5.Domain.Common; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace EntityFrameworkNet5.Domain 9 | { 10 | public class Coach : BaseDomainObject 11 | { 12 | public string Name { get; set; } 13 | public int? TeamId { get; set; } 14 | public virtual Team Team { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Domain/Common/BaseDomainObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace EntityFrameworkNet5.Domain.Common 8 | { 9 | public abstract class BaseDomainObject 10 | { 11 | public int Id { get; set; } 12 | public DateTime CreatedDate { get; set; } 13 | 14 | public DateTime ModifiedDate { get; set; } 15 | public string CreatedBy { get; set; } 16 | public string ModifiedBy { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Domain/EntityFrameworkNet5.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Domain/League.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkNet5.Domain.Common; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace EntityFrameworkNet5.Domain 9 | { 10 | public class League : BaseDomainObject 11 | { 12 | public string Name { get; set; } 13 | public List Teams { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Domain/Match.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkNet5.Domain.Common; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace EntityFrameworkNet5.Domain 9 | { 10 | public class Match : BaseDomainObject 11 | { 12 | public int HomeTeamId { get; set; } 13 | public virtual Team HomeTeam { get; set; } 14 | public int AwayTeamId { get; set; } 15 | public virtual Team AwayTeam { get; set; } 16 | 17 | public DateTime Date { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Domain/Models/TeamDetail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace EntityFrameworkNet5.Domain.Models 8 | { 9 | public class TeamDetail 10 | { 11 | public string Name { get; set; } 12 | public string CoachName { get; set; } 13 | public string LeagueName { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Domain/Team.cs: -------------------------------------------------------------------------------- 1 | using EntityFrameworkNet5.Domain.Common; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace EntityFrameworkNet5.Domain 9 | { 10 | public class Team : BaseDomainObject 11 | { 12 | public string Name { get; set; } 13 | public int LeagueId { get; set; } 14 | public virtual League League { get; set; } 15 | public virtual Coach Coach { get; set; } 16 | 17 | public virtual List HomeMatches { get; set; } 18 | public virtual List AwayMatches { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.Domain/TeamsCoachesLeaguesView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace EntityFrameworkNet5.Domain 8 | { 9 | public class TeamsCoachesLeaguesView 10 | { 11 | public string Name { get; set; } 12 | public string CoachName { get; set; } 13 | public string LeagueName { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /EntityFrameworkNet5.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31402.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkNet5.ConsoleApp", "EntityFrameworkNet5.ConsoleApp\EntityFrameworkNet5.ConsoleApp.csproj", "{02DC1A06-7862-4F30-B1B5-5722243DE32C}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkNet5.Data", "EntityFrameworkNet5.Data\EntityFrameworkNet5.Data.csproj", "{F59C9347-5569-4276-9ACB-5BEACC9A8E63}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkNet5.Domain", "EntityFrameworkNet5.Domain\EntityFrameworkNet5.Domain.csproj", "{E9D9982F-24DA-4DB2-A59E-97509B548EAA}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {02DC1A06-7862-4F30-B1B5-5722243DE32C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {02DC1A06-7862-4F30-B1B5-5722243DE32C}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {02DC1A06-7862-4F30-B1B5-5722243DE32C}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {02DC1A06-7862-4F30-B1B5-5722243DE32C}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {F59C9347-5569-4276-9ACB-5BEACC9A8E63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {F59C9347-5569-4276-9ACB-5BEACC9A8E63}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {F59C9347-5569-4276-9ACB-5BEACC9A8E63}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {F59C9347-5569-4276-9ACB-5BEACC9A8E63}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {E9D9982F-24DA-4DB2-A59E-97509B548EAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {E9D9982F-24DA-4DB2-A59E-97509B548EAA}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {E9D9982F-24DA-4DB2-A59E-97509B548EAA}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {E9D9982F-24DA-4DB2-A59E-97509B548EAA}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {F6BCF5F6-1580-4E46-B7BC-0E376F993900} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Entity Framework Core - A Full Tour Supporting Files 2 | 3 | In this course, Entity Framework Core - A Full Tour, you will learn to work with data in your .NET applications. 4 | 5 | Most times when course are created for .NET technologies, the details of Entity Framework and it's sheer power are neglected. We get distracted with abstractions and layers and don't focus on what Entity Framework is doing and can do. 6 | 7 | In this course, we will review the general benefits of using Entity Framework Core 5, which is Microsoft’s flagship Object Relational Mapper (ORM), to relieve you of many concerns and challenges that come with this component of software development. We will also spend time discovering how to EF Core translates classes and references to Database Models and Relationships. 8 | 9 | We will learn how to write queries, update databases incrementally, rollback changes and explore the myriad capabilities that Entity Framework Core affords us. 10 | 11 | When you’re finished with this course, you’ll have the skills and knowledge of Entity Framework Core needed to fluidly interact with data and write quires for for .NET Core applications with ease. 12 | 13 | By the end of watching this course, you'll be able to: 14 |
    15 |
  • Construct a data model using code-first and database-first workflows
  • 16 |
  • Understand Entity Framework Commands
  • 17 |
  • Use migrations to manage database changes
  • 18 |
  • Apply Database validations and constraints
  • 19 |
  • Perform CRUD operations using LINQ
  • 20 |
  • Apply best practices with Entity Framework
  • 21 |
  • Extending Data Contexts
  • 22 |
  • Understand how Change Tracking works.
  • 23 |
  • Manage Database Structure using Fluent API
  • 24 |
  • Handle One-To-One, One-To-Many and Many-To-Many Relationships
  • 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | --------------------------------------------------------------------------------