Compare commits

..

22 Commits

Author SHA1 Message Date
024f9da8f9 Update README. 2025-04-14 22:33:11 +02:00
2d14366feb Add retry option for SQL server example. 2025-04-14 22:33:02 +02:00
b32e390c5c Add SQLite timeout option. 2025-04-14 22:32:32 +02:00
30d69e9f79 Create query filter for soft delete on League and add an example function. 2025-04-14 22:24:46 +02:00
02d8477b05 Create migration for League soft delete flag. 2025-04-14 22:14:12 +02:00
bcb084d733 Add soft delete flag to League model. 2025-04-14 22:13:48 +02:00
f02538b281 Create migrations for concurrency tokens. 2025-04-14 22:11:01 +02:00
2a09ddb0da Add concurrency checks.
See also:
https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=data-annotations
2025-04-14 22:10:45 +02:00
f6d5733992 Add example with transaction security with save points. 2025-04-14 21:49:44 +02:00
feafaba447 Override ConfigureConventions to apply global restrictions on models. 2025-04-14 21:49:18 +02:00
8a4e8a41f3 Add migration for restrictions.
Note that I had to remove the view from the table manually, otherwise I could not update the database.
2025-04-14 21:30:34 +02:00
e4b92dedef Add restrictions in configuration and data annotations. 2025-04-14 21:29:56 +02:00
5b90fa1242 Override SaveChangesAsync to automatically add audit data. 2025-04-14 17:12:15 +02:00
d67d05d6a2 Use DbContext with options. 2025-04-14 16:54:50 +02:00
cbcfb5536d Improve get Team by Id and include Coach and League.
Also add IgnoreCycles to options to prevent recursive problem.
2025-04-14 13:15:53 +02:00
30c3621deb Return TeamDto instead of Team model for API. 2025-04-14 13:03:30 +02:00
f8d1ddd758 Map controllers to program.cs file.
http://localhost:5072/api/teams
2025-04-14 12:52:02 +02:00
4176958f17 Remove Weatherforecast example code. 2025-04-14 12:50:30 +02:00
2934b45018 Optimise delete code with only 1 trip to database. 2025-04-14 11:57:59 +02:00
16ddb2d336 Scaffold TeamsController in API project.
dotnet aspnet-codegenerator controller -name TeamsController -async -api -m Team -dc DeadBallZoneLeagueDbContext -outDir Controllers -dbProvider sqlite
2025-04-14 11:44:22 +02:00
8fc6bc96c0 Create new DbContext constructor with external Options.
And install related packages.
2025-04-14 10:50:13 +02:00
ba77fbd176 Update README with ASP.NET info. 2025-04-08 23:03:37 +02:00
21 changed files with 2610 additions and 77 deletions

View File

@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using EntityFrameworkCore.Data;
using EntityFrameworkCore.Domain;
namespace EntityFrameworkCore.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class TeamsController : ControllerBase
{
private readonly DeadBallZoneLeagueDbContext _context;
public TeamsController(DeadBallZoneLeagueDbContext context)
{
_context = context;
}
// GET: api/Teams
[HttpGet]
public async Task<ActionResult<IEnumerable<TeamDto>>> GetTeams()
{
if (_context.Teams == null)
{
return NotFound();
}
var teams = await _context.Teams
.Select(t => new TeamDto
{
Id = t.Id,
Name = t.Name,
CoachName = t.Coach.Name
})
.ToListAsync();
return teams;
}
// GET: api/Teams/5
[HttpGet("{id}")]
public async Task<ActionResult<Team>> GetTeam(int id)
{
if (_context.Teams == null)
{
return NotFound();
}
// using λ for fun here.
var team = await _context.Teams
.Include(λ => λ.Coach)
.Include(λ => λ.League)
.FirstOrDefaultAsync(λ => λ.Id == id);
if (team == null)
{
return NotFound();
}
return team;
}
// PUT: api/Teams/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutTeam(int id, Team team)
{
if (id != team.Id)
{
return BadRequest();
}
_context.Entry(team).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!TeamExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Teams
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Team>> PostTeam(Team team)
{
_context.Teams.Add(team);
await _context.SaveChangesAsync();
return CreatedAtAction("GetTeam", new { id = team.Id }, team);
}
// DELETE: api/Teams/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteTeam(int id)
{
if (_context.Teams == null)
{
return NotFound();
}
await _context.Teams.Where(t => t.Id == id).ExecuteDeleteAsync();
return NoContent();
}
private bool TeamExists(int id)
{
return _context.Teams.Any(e => e.Id == id);
}
}
}

View File

@ -8,6 +8,19 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../EntityFrameworkCore.Data/EntityFrameworkCore.Data.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,8 @@
namespace EntityFrameworkCore.API;
public class TeamDto
{
public int Id { get; set; }
public string Name { get; set; }
public string CoachName { get; set; }
}

View File

@ -1,9 +1,42 @@
using EntityFrameworkCore.Data;
using Microsoft.EntityFrameworkCore;
using System.Text.Json.Serialization;
using EntityFrameworkCore.API.Controllers;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers().AddJsonOptions(options =>
{
// IgnoreCycles prevents "System.Text.Json.JsonException: A possible object cycle was detected".
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
});
// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
var sqliteDatabaseName = builder.Configuration.GetConnectionString("SqliteDatabaseName");
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
var dbPath = Path.Combine(path, sqliteDatabaseName);
var connectionString = $"Data Source={dbPath}";
builder.Services.AddDbContext<DeadBallZoneLeagueDbContext>(options => {
options.UseSqlite(connectionString, sqliteOptions => {
sqliteOptions.CommandTimeout(30); // 30 second timeout.
})
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
.LogTo(Console.WriteLine, LogLevel.Information);
if (!builder.Environment.IsProduction())
{
// Do not allow this in Production.
options.EnableSensitiveDataLogging();
options.EnableDetailedErrors();
}
});
var app = builder.Build();
// Configure the HTTP request pipeline.
@ -14,28 +47,6 @@ if (app.Environment.IsDevelopment())
app.UseHttpsRedirection();
var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithName("GetWeatherForecast");
app.MapControllers();
app.Run();
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}

View File

@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ConnectionStrings": {
"SqliteDatabaseName": "DeadBallZoneLeague_EFCore.db"
}
}

View File

@ -3,7 +3,13 @@ using EntityFrameworkCore.Domain;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using var context = new DeadBallZoneLeagueDbContext();
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
var dbPath = Path.Combine(path, "DeadBallZoneLeague_EFCore.db");
var optionsBuilder = new DbContextOptionsBuilder<DeadBallZoneLeagueDbContext>();
optionsBuilder.UseSqlite($"Data Source={dbPath}");
using var context = new DeadBallZoneLeagueDbContext(optionsBuilder.Options);
// context.Database.Migrate(); // Can be used to automatically migrate on run.
context.Database.EnsureCreated();
@ -16,6 +22,90 @@ context.Database.EnsureCreated();
// Rather than raise: "System.InvalidOperationException: Sequence contains no elements."
// var firstCoach = await context.Coaches.FirstOrDefaultAsync();
async Task SoftDeleteLeague()
{
var league = context.Leagues.Find(1);
league.IsDeleted = true;
context.SaveChanges();
// This is rather cumbersome. Instead, use a query filter. See League configuration.
//var leagues = context.Leagues.Where(l => !l.IsDeleted).ToList();
// This now gets all leagues, with query filters applied.
var leagues = context.Leagues.ToList();
// You can also ignore them, if you want in a specific case.
leagues = context.Leagues.IgnoreQueryFilters().ToList();
}
async Task ConcurrencyCheckExample()
{
var team = context.Teams.Find(1);
team.Name = "New name";
// To simulate a concurrency change, add a breakpoint and
// manually update the GUID in the database before SaveChangesAsync is called.
// See also: https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=data-annotations
try
{
await context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException ex)
{
Console.WriteLine(ex.Message);
}
}
async Task TransactionWithSavepoint()
{
var transaction = context.Database.BeginTransaction();
var league = new League
{
Name = "Geosphere league"
};
context.Add(league);
context.SaveChanges();
transaction.CreateSavepoint("CreatedLeague");
var coach = new Coach
{
Name = "Brad Ironfist"
};
context.Add(coach);
context.SaveChanges();
var teams = new List<Team>
{
new Team
{
Name = "Dominators",
LeagueId = league.Id,
CoachId = coach.Id
}
};
context.AddRange(teams);
context.SaveChanges();
try
{
transaction.Commit();
}
catch (Exception)
{
// Rollback everything.
//transaction.Rollback();
// Or rollback to a specific save point.
transaction.RollbackToSavepoint("CreatedLeague");
throw;
}
}
async Task UserDefinedQuery()
{

View File

@ -8,6 +8,10 @@ public class LeagueConfiguration : IEntityTypeConfiguration<League>
{
public void Configure(EntityTypeBuilder<League> builder)
{
// This query filter will be always applied.
// Note that you should call HasQueryFilter only once, otherwise the filter is overwritten.
builder.HasQueryFilter(l => l.IsDeleted == false);
builder.HasData(
new League { Id = 1, Name = "Local League", CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33)},
new League { Id = 2, Name = "National League", CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33)},

View File

@ -10,6 +10,17 @@ public class TeamConfiguration : IEntityTypeConfiguration<Team>
{
builder.HasIndex(t => t.Name).IsUnique();
// example composite key configuration.
// builder.HasIndex(λ => new { λ.CoachId, λ.LeagueId }).IsUnique();
// SQL Server method to setup concurrency.
// builder.Property(λ => λ.Version).IsRowVersion();
// SQLite (and other) method to setup concurrency. See also BaseDomain model.
builder.Property(λ => λ.Version).IsConcurrencyToken();
builder.Property(λ => λ.Name).HasMaxLength(100).IsRequired();
builder.HasMany(m => m.HomeMatches) // A team has many home matches.
.WithOne(m => m.HomeTeam) // Mapped to the HomeTeam property.
.HasForeignKey(m => m.HomeTeamId)

View File

@ -1,36 +1,26 @@
using Microsoft.EntityFrameworkCore;
using EntityFrameworkCore.Domain;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Design;
namespace EntityFrameworkCore.Data;
public class DeadBallZoneLeagueDbContext : DbContext
{
private string DbPath;
public DeadBallZoneLeagueDbContext()
public DeadBallZoneLeagueDbContext(DbContextOptions<DeadBallZoneLeagueDbContext> options) : base(options)
{
// In Ubuntu 24.04, the file is created here: /home/user/.local/share
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
DbPath = Path.Combine(path, "DeadBallZoneLeague_EFCore.db");
// This constuctor allows it to accept the options set from other instances, such as in the API project.
}
public DbSet<Team> Teams { get; set; }
public DbSet<Coach> Coaches { get; set; }
public DbSet<League> Leagues { get; set; }
public DbSet<Match> Matches { get; set; }
public DbSet<TeamsAndLeaguesView> TeamsAndLeaguesView { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite($"Data source={DbPath}")
// .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) // Do not use tracking, set globally on all queries.
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging() // Do not allow this in Production.
.EnableDetailedErrors(); // Do not allow this in Production.
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// modelBuilder.ApplyConfiguration(new TeamConfiguration());
@ -52,5 +42,63 @@ public class DeadBallZoneLeagueDbContext : DbContext
.HasName("GetEarliestMatch");
}
// This is an example override for SQL Server:
// protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=FootballLeague_EfCore; Encrypt=true", sqlOptions => {
// sqlOptions.EnableRetryOnFailure(maxRetryCount: 5,
// maxRetryDelay: TimeSpan.FromSeconds(5),
// errorNumbersToAdd: null);
// });
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
// These apply to all the settings for all models.
configurationBuilder.Properties<string>().HaveMaxLength(100);
configurationBuilder.Properties<decimal>().HavePrecision(16, 2);
}
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
var entries = ChangeTracker.Entries<BaseDomainModel>().Where(
λ => λ.State == EntityState.Modified || λ.State == EntityState.Added
);
// Whenever a save is made to an entity, these fields are now automatically updated:
foreach (var entry in entries)
{
entry.Entity.ModifiedDate = DateTime.UtcNow;
entry.Entity.ModifiedBy = "Sample User 1";
if (entry.State == EntityState.Added)
{
entry.Entity.CreatedDate = DateTime.UtcNow;
entry.Entity.CreatedBy = "Sample User";
}
// Update the concurrency token.
entry.Entity.Version = Guid.NewGuid();
}
return base.SaveChangesAsync(cancellationToken);
}
public DateTime GetEarliestTeamMatch(int teamId) => throw new NotImplementedException();
}
public class DeadBallZoneLeagueDbContextFactory : IDesignTimeDbContextFactory<DeadBallZoneLeagueDbContext>
{
public DeadBallZoneLeagueDbContext CreateDbContext(string[] args)
{
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
var dbPath = Path.Combine(path, configuration.GetConnectionString("SqliteDatabaseName"));
var optionsBuilder = new DbContextOptionsBuilder<DeadBallZoneLeagueDbContext>();
optionsBuilder.UseSqlite($"Data Source={dbPath}");
return new DeadBallZoneLeagueDbContext(optionsBuilder.Options);
}
}

View File

@ -9,6 +9,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.3" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,506 @@
// <auto-generated />
using System;
using EntityFrameworkCore.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameworkCore.Data.Migrations
{
[DbContext(typeof(DeadBallZoneLeagueDbContext))]
[Migration("20250414192903_AddRestriction")]
partial class AddRestriction
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.3");
modelBuilder.Entity("EntityFrameworkCore.Domain.Coach", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<string>("ModifiedBy")
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Coaches");
b.HasData(
new
{
Id = 1,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Christian Southgate"
},
new
{
Id = 2,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Rob Mann"
},
new
{
Id = 3,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Jon Curtis"
},
new
{
Id = 4,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Andy Taylor"
},
new
{
Id = 5,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Steve Johnson"
},
new
{
Id = 6,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Dan Cook"
},
new
{
Id = 7,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Ken Jarvis"
},
new
{
Id = 8,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Kenny Suzuki"
},
new
{
Id = 9,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Gordon Hall"
},
new
{
Id = 10,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "John O Dowd"
},
new
{
Id = 11,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Julian Widdows"
},
new
{
Id = 12,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Andy Williams"
},
new
{
Id = 13,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Trevor Williams"
},
new
{
Id = 14,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Blake Deathray"
},
new
{
Id = 15,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Rock Housebrick"
});
});
modelBuilder.Entity("EntityFrameworkCore.Domain.League", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<string>("ModifiedBy")
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Leagues");
b.HasData(
new
{
Id = 1,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Local League"
},
new
{
Id = 2,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "National League"
},
new
{
Id = 3,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Geosphere"
},
new
{
Id = 4,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Cyber war"
});
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Match", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("AwayTeamId")
.HasColumnType("INTEGER");
b.Property<int>("AwayTeamScore")
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<DateTime>("Date")
.HasColumnType("TEXT");
b.Property<int>("HomeTeamId")
.HasColumnType("INTEGER");
b.Property<int>("HomeTeamScore")
.HasColumnType("INTEGER");
b.Property<string>("ModifiedBy")
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<decimal>("TicketPrice")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("AwayTeamId");
b.HasIndex("HomeTeamId");
b.ToTable("Matches");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Team", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CoachId")
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<int?>("LeagueId")
.HasColumnType("INTEGER");
b.Property<string>("ModifiedBy")
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CoachId")
.IsUnique();
b.HasIndex("LeagueId");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Teams");
b.HasData(
new
{
Id = 1,
CoachId = 1,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 2,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Delhi"
},
new
{
Id = 2,
CoachId = 2,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Voodoo"
},
new
{
Id = 3,
CoachId = 3,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Penal X"
},
new
{
Id = 4,
CoachId = 4,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 3,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Tokyo"
},
new
{
Id = 5,
CoachId = 5,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 2,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Barcelona"
},
new
{
Id = 6,
CoachId = 6,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 2,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Manchester"
},
new
{
Id = 7,
CoachId = 7,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 3,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Bangkok"
},
new
{
Id = 8,
CoachId = 8,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 3,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Amsterdam"
},
new
{
Id = 9,
CoachId = 9,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Killaklowns"
},
new
{
Id = 10,
CoachId = 10,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Sol"
},
new
{
Id = 11,
CoachId = 11,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 4,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "DEC"
},
new
{
Id = 12,
CoachId = 12,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Leopards"
},
new
{
Id = 13,
CoachId = 13,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Harlequins"
},
new
{
Id = 14,
CoachId = 14,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 4,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Gladiators"
},
new
{
Id = 15,
CoachId = 15,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Fiz-O"
});
});
modelBuilder.Entity("EntityFrameworkCore.Domain.TeamsAndLeaguesView", b =>
{
b.Property<string>("LeagueName")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.ToTable((string)null);
b.ToView("vw_TeamsAndLeagues", (string)null);
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Match", b =>
{
b.HasOne("EntityFrameworkCore.Domain.Team", "AwayTeam")
.WithMany("AwayMatches")
.HasForeignKey("AwayTeamId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("EntityFrameworkCore.Domain.Team", "HomeTeam")
.WithMany("HomeMatches")
.HasForeignKey("HomeTeamId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("AwayTeam");
b.Navigation("HomeTeam");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Team", b =>
{
b.HasOne("EntityFrameworkCore.Domain.Coach", "Coach")
.WithOne("Team")
.HasForeignKey("EntityFrameworkCore.Domain.Team", "CoachId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameworkCore.Domain.League", "League")
.WithMany("Teams")
.HasForeignKey("LeagueId");
b.Navigation("Coach");
b.Navigation("League");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Coach", b =>
{
b.Navigation("Team");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.League", b =>
{
b.Navigation("Teams");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Team", b =>
{
b.Navigation("AwayMatches");
b.Navigation("HomeMatches");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameworkCore.Data.Migrations
{
/// <inheritdoc />
public partial class AddRestriction : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Teams",
type: "TEXT",
maxLength: 100,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "TEXT",
oldNullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Teams",
type: "TEXT",
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT",
oldMaxLength: 100);
}
}
}

View File

@ -0,0 +1,568 @@
// <auto-generated />
using System;
using EntityFrameworkCore.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameworkCore.Data.Migrations
{
[DbContext(typeof(DeadBallZoneLeagueDbContext))]
[Migration("20250414200332_AddConcurrencyCheckVersionToken")]
partial class AddConcurrencyCheckVersionToken
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.3");
modelBuilder.Entity("EntityFrameworkCore.Domain.Coach", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<string>("ModifiedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Coaches");
b.HasData(
new
{
Id = 1,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Christian Southgate",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 2,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Rob Mann",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 3,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Jon Curtis",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 4,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Andy Taylor",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 5,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Steve Johnson",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 6,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Dan Cook",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 7,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Ken Jarvis",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 8,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Kenny Suzuki",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 9,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Gordon Hall",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 10,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "John O Dowd",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 11,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Julian Widdows",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 12,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Andy Williams",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 13,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Trevor Williams",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 14,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Blake Deathray",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 15,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Rock Housebrick",
Version = new Guid("00000000-0000-0000-0000-000000000000")
});
});
modelBuilder.Entity("EntityFrameworkCore.Domain.League", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<string>("ModifiedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Leagues");
b.HasData(
new
{
Id = 1,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Local League",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 2,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "National League",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 3,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Geosphere",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 4,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Cyber war",
Version = new Guid("00000000-0000-0000-0000-000000000000")
});
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Match", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("AwayTeamId")
.HasColumnType("INTEGER");
b.Property<int>("AwayTeamScore")
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<DateTime>("Date")
.HasColumnType("TEXT");
b.Property<int>("HomeTeamId")
.HasColumnType("INTEGER");
b.Property<int>("HomeTeamScore")
.HasColumnType("INTEGER");
b.Property<string>("ModifiedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<decimal>("TicketPrice")
.HasPrecision(16, 2)
.HasColumnType("TEXT");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("AwayTeamId");
b.HasIndex("HomeTeamId");
b.ToTable("Matches");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Team", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CoachId")
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<int?>("LeagueId")
.HasColumnType("INTEGER");
b.Property<string>("ModifiedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CoachId")
.IsUnique();
b.HasIndex("LeagueId");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Teams");
b.HasData(
new
{
Id = 1,
CoachId = 1,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 2,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Delhi",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 2,
CoachId = 2,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Voodoo",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 3,
CoachId = 3,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Penal X",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 4,
CoachId = 4,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 3,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Tokyo",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 5,
CoachId = 5,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 2,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Barcelona",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 6,
CoachId = 6,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 2,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Manchester",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 7,
CoachId = 7,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 3,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Bangkok",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 8,
CoachId = 8,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 3,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Amsterdam",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 9,
CoachId = 9,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Killaklowns",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 10,
CoachId = 10,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Sol",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 11,
CoachId = 11,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 4,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "DEC",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 12,
CoachId = 12,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Leopards",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 13,
CoachId = 13,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Harlequins",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 14,
CoachId = 14,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 4,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Gladiators",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 15,
CoachId = 15,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Fiz-O",
Version = new Guid("00000000-0000-0000-0000-000000000000")
});
});
modelBuilder.Entity("EntityFrameworkCore.Domain.TeamsAndLeaguesView", b =>
{
b.Property<string>("LeagueName")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.ToTable((string)null);
b.ToView("vw_TeamsAndLeagues", (string)null);
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Match", b =>
{
b.HasOne("EntityFrameworkCore.Domain.Team", "AwayTeam")
.WithMany("AwayMatches")
.HasForeignKey("AwayTeamId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("EntityFrameworkCore.Domain.Team", "HomeTeam")
.WithMany("HomeMatches")
.HasForeignKey("HomeTeamId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("AwayTeam");
b.Navigation("HomeTeam");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Team", b =>
{
b.HasOne("EntityFrameworkCore.Domain.Coach", "Coach")
.WithOne("Team")
.HasForeignKey("EntityFrameworkCore.Domain.Team", "CoachId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameworkCore.Domain.League", "League")
.WithMany("Teams")
.HasForeignKey("LeagueId");
b.Navigation("Coach");
b.Navigation("League");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Coach", b =>
{
b.Navigation("Team");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.League", b =>
{
b.Navigation("Teams");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Team", b =>
{
b.Navigation("AwayMatches");
b.Navigation("HomeMatches");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,301 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameworkCore.Data.Migrations
{
/// <inheritdoc />
public partial class AddConcurrencyCheckVersionToken : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "Version",
table: "Teams",
type: "TEXT",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.AddColumn<Guid>(
name: "Version",
table: "Matches",
type: "TEXT",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.AddColumn<Guid>(
name: "Version",
table: "Leagues",
type: "TEXT",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.AddColumn<Guid>(
name: "Version",
table: "Coaches",
type: "TEXT",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 1,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 2,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 3,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 4,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 5,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 6,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 7,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 8,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 9,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 10,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 11,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 12,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 13,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 14,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Coaches",
keyColumn: "Id",
keyValue: 15,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Leagues",
keyColumn: "Id",
keyValue: 1,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Leagues",
keyColumn: "Id",
keyValue: 2,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Leagues",
keyColumn: "Id",
keyValue: 3,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Leagues",
keyColumn: "Id",
keyValue: 4,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 1,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 2,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 3,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 4,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 5,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 6,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 7,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 8,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 9,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 10,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 11,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 12,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 13,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 14,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.UpdateData(
table: "Teams",
keyColumn: "Id",
keyValue: 15,
column: "Version",
value: new Guid("00000000-0000-0000-0000-000000000000"));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Version",
table: "Teams");
migrationBuilder.DropColumn(
name: "Version",
table: "Matches");
migrationBuilder.DropColumn(
name: "Version",
table: "Leagues");
migrationBuilder.DropColumn(
name: "Version",
table: "Coaches");
}
}
}

View File

@ -0,0 +1,575 @@
// <auto-generated />
using System;
using EntityFrameworkCore.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameworkCore.Data.Migrations
{
[DbContext(typeof(DeadBallZoneLeagueDbContext))]
[Migration("20250414201323_AddSoftDeleteFlagLeague")]
partial class AddSoftDeleteFlagLeague
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.3");
modelBuilder.Entity("EntityFrameworkCore.Domain.Coach", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<string>("ModifiedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Coaches");
b.HasData(
new
{
Id = 1,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Christian Southgate",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 2,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Rob Mann",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 3,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Jon Curtis",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 4,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Andy Taylor",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 5,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Steve Johnson",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 6,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Dan Cook",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 7,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Ken Jarvis",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 8,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Kenny Suzuki",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 9,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Gordon Hall",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 10,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "John O Dowd",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 11,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Julian Widdows",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 12,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Andy Williams",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 13,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Trevor Williams",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 14,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Blake Deathray",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 15,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Rock Housebrick",
Version = new Guid("00000000-0000-0000-0000-000000000000")
});
});
modelBuilder.Entity("EntityFrameworkCore.Domain.League", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<bool>("IsDeleted")
.HasColumnType("INTEGER");
b.Property<string>("ModifiedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Leagues");
b.HasData(
new
{
Id = 1,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
IsDeleted = false,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Local League",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 2,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
IsDeleted = false,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "National League",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 3,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
IsDeleted = false,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Geosphere",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 4,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
IsDeleted = false,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Cyber war",
Version = new Guid("00000000-0000-0000-0000-000000000000")
});
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Match", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("AwayTeamId")
.HasColumnType("INTEGER");
b.Property<int>("AwayTeamScore")
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<DateTime>("Date")
.HasColumnType("TEXT");
b.Property<int>("HomeTeamId")
.HasColumnType("INTEGER");
b.Property<int>("HomeTeamScore")
.HasColumnType("INTEGER");
b.Property<string>("ModifiedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<decimal>("TicketPrice")
.HasPrecision(16, 2)
.HasColumnType("TEXT");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("AwayTeamId");
b.HasIndex("HomeTeamId");
b.ToTable("Matches");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Team", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CoachId")
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<int?>("LeagueId")
.HasColumnType("INTEGER");
b.Property<string>("ModifiedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CoachId")
.IsUnique();
b.HasIndex("LeagueId");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Teams");
b.HasData(
new
{
Id = 1,
CoachId = 1,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 2,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Delhi",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 2,
CoachId = 2,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Voodoo",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 3,
CoachId = 3,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Penal X",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 4,
CoachId = 4,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 3,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Tokyo",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 5,
CoachId = 5,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 2,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Barcelona",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 6,
CoachId = 6,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 2,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Manchester",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 7,
CoachId = 7,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 3,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Bangkok",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 8,
CoachId = 8,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 3,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Amsterdam",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 9,
CoachId = 9,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Killaklowns",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 10,
CoachId = 10,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Sol",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 11,
CoachId = 11,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 4,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "DEC",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 12,
CoachId = 12,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Leopards",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 13,
CoachId = 13,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Harlequins",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 14,
CoachId = 14,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 4,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Gladiators",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 15,
CoachId = 15,
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Fiz-O",
Version = new Guid("00000000-0000-0000-0000-000000000000")
});
});
modelBuilder.Entity("EntityFrameworkCore.Domain.TeamsAndLeaguesView", b =>
{
b.Property<string>("LeagueName")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.ToTable((string)null);
b.ToView("vw_TeamsAndLeagues", (string)null);
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Match", b =>
{
b.HasOne("EntityFrameworkCore.Domain.Team", "AwayTeam")
.WithMany("AwayMatches")
.HasForeignKey("AwayTeamId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("EntityFrameworkCore.Domain.Team", "HomeTeam")
.WithMany("HomeMatches")
.HasForeignKey("HomeTeamId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("AwayTeam");
b.Navigation("HomeTeam");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Team", b =>
{
b.HasOne("EntityFrameworkCore.Domain.Coach", "Coach")
.WithOne("Team")
.HasForeignKey("EntityFrameworkCore.Domain.Team", "CoachId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameworkCore.Domain.League", "League")
.WithMany("Teams")
.HasForeignKey("LeagueId");
b.Navigation("Coach");
b.Navigation("League");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Coach", b =>
{
b.Navigation("Team");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.League", b =>
{
b.Navigation("Teams");
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Team", b =>
{
b.Navigation("AwayMatches");
b.Navigation("HomeMatches");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,57 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameworkCore.Data.Migrations
{
/// <inheritdoc />
public partial class AddSoftDeleteFlagLeague : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsDeleted",
table: "Leagues",
type: "INTEGER",
nullable: false,
defaultValue: false);
migrationBuilder.UpdateData(
table: "Leagues",
keyColumn: "Id",
keyValue: 1,
column: "IsDeleted",
value: false);
migrationBuilder.UpdateData(
table: "Leagues",
keyColumn: "Id",
keyValue: 2,
column: "IsDeleted",
value: false);
migrationBuilder.UpdateData(
table: "Leagues",
keyColumn: "Id",
keyValue: 3,
column: "IsDeleted",
value: false);
migrationBuilder.UpdateData(
table: "Leagues",
keyColumn: "Id",
keyValue: 4,
column: "IsDeleted",
value: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsDeleted",
table: "Leagues");
}
}
}

View File

@ -24,12 +24,14 @@ namespace EntityFrameworkCore.Data.Migrations
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<string>("ModifiedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
@ -37,6 +39,11 @@ namespace EntityFrameworkCore.Data.Migrations
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.HasKey("Id");
@ -49,105 +56,120 @@ namespace EntityFrameworkCore.Data.Migrations
Id = 1,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Christian Southgate"
Name = "Christian Southgate",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 2,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Rob Mann"
Name = "Rob Mann",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 3,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Jon Curtis"
Name = "Jon Curtis",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 4,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Andy Taylor"
Name = "Andy Taylor",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 5,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Steve Johnson"
Name = "Steve Johnson",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 6,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Dan Cook"
Name = "Dan Cook",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 7,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Ken Jarvis"
Name = "Ken Jarvis",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 8,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Kenny Suzuki"
Name = "Kenny Suzuki",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 9,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Gordon Hall"
Name = "Gordon Hall",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 10,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "John O Dowd"
Name = "John O Dowd",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 11,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Julian Widdows"
Name = "Julian Widdows",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 12,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Andy Williams"
Name = "Andy Williams",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 13,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Trevor Williams"
Name = "Trevor Williams",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 14,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Blake Deathray"
Name = "Blake Deathray",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 15,
CreatedDate = new DateTime(2025, 4, 7, 17, 7, 27, 33, DateTimeKind.Unspecified),
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Rock Housebrick"
Name = "Rock Housebrick",
Version = new Guid("00000000-0000-0000-0000-000000000000")
});
});
@ -158,18 +180,28 @@ namespace EntityFrameworkCore.Data.Migrations
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
.HasColumnType("TEXT");
b.Property<bool>("IsDeleted")
.HasColumnType("INTEGER");
b.Property<string>("ModifiedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.HasKey("Id");
@ -181,29 +213,37 @@ namespace EntityFrameworkCore.Data.Migrations
{
Id = 1,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
IsDeleted = false,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Local League"
Name = "Local League",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 2,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
IsDeleted = false,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "National League"
Name = "National League",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 3,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
IsDeleted = false,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Geosphere"
Name = "Geosphere",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
Id = 4,
CreatedDate = new DateTime(2025, 4, 6, 17, 7, 27, 33, DateTimeKind.Unspecified),
IsDeleted = false,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Cyber war"
Name = "Cyber war",
Version = new Guid("00000000-0000-0000-0000-000000000000")
});
});
@ -220,6 +260,7 @@ namespace EntityFrameworkCore.Data.Migrations
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
@ -235,12 +276,18 @@ namespace EntityFrameworkCore.Data.Migrations
.HasColumnType("INTEGER");
b.Property<string>("ModifiedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<decimal>("TicketPrice")
.HasPrecision(16, 2)
.HasColumnType("TEXT");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.HasKey("Id");
@ -262,6 +309,7 @@ namespace EntityFrameworkCore.Data.Migrations
.HasColumnType("INTEGER");
b.Property<string>("CreatedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedDate")
@ -271,12 +319,19 @@ namespace EntityFrameworkCore.Data.Migrations
.HasColumnType("INTEGER");
b.Property<string>("ModifiedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.HasKey("Id");
@ -299,7 +354,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 2,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Delhi"
Name = "Neo Delhi",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -308,7 +364,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Voodoo"
Name = "Voodoo",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -317,7 +374,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Penal X"
Name = "Penal X",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -326,7 +384,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 3,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Tokyo"
Name = "Neo Tokyo",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -335,7 +394,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 2,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Barcelona"
Name = "Neo Barcelona",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -344,7 +404,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 2,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Manchester"
Name = "Neo Manchester",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -353,7 +414,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 3,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Bangkok"
Name = "Neo Bangkok",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -362,7 +424,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 3,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Neo Amsterdam"
Name = "Neo Amsterdam",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -371,7 +434,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Killaklowns"
Name = "Killaklowns",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -380,7 +444,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Sol"
Name = "Sol",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -389,7 +454,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 4,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "DEC"
Name = "DEC",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -398,7 +464,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Leopards"
Name = "Leopards",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -407,7 +474,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Harlequins"
Name = "Harlequins",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -416,7 +484,8 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 4,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Gladiators"
Name = "Gladiators",
Version = new Guid("00000000-0000-0000-0000-000000000000")
},
new
{
@ -425,10 +494,26 @@ namespace EntityFrameworkCore.Data.Migrations
CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33, DateTimeKind.Unspecified),
LeagueId = 1,
ModifiedDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Name = "Fiz-O"
Name = "Fiz-O",
Version = new Guid("00000000-0000-0000-0000-000000000000")
});
});
modelBuilder.Entity("EntityFrameworkCore.Domain.TeamsAndLeaguesView", b =>
{
b.Property<string>("LeagueName")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.ToTable((string)null);
b.ToView("vw_TeamsAndLeagues", (string)null);
});
modelBuilder.Entity("EntityFrameworkCore.Domain.Match", b =>
{
b.HasOne("EntityFrameworkCore.Domain.Team", "AwayTeam")

View File

@ -1,4 +1,6 @@
namespace EntityFrameworkCore.Domain;
using System.ComponentModel.DataAnnotations;
namespace EntityFrameworkCore.Domain;
// Since C#11, you do not need to wrap in accolades anymore.
public abstract class BaseDomainModel
{
@ -7,4 +9,12 @@ public abstract class BaseDomainModel
public DateTime ModifiedDate { get; set;}
public string? CreatedBy { get; set; }
public string? ModifiedBy { get; set; }
// SQL Server method to setup concurrency column.
// [Timestamp]
// public byte[] Version { get; set; }
// SQLite (and other) method to setup concurrency column.
[ConcurrencyCheck]
public Guid Version { get; set; }
}

View File

@ -1,7 +1,11 @@
namespace EntityFrameworkCore.Domain;
using System.ComponentModel.DataAnnotations;
namespace EntityFrameworkCore.Domain;
// Since C#11, you do not need to wrap in accolades anymore.
public class Coach : BaseDomainModel
{
[MaxLength(100)]
[Required]
public string Name { get; set; } // Strings are automatically become VARCHAR database types.
public Team? Team { get; set; }
}

View File

@ -3,5 +3,6 @@
public class League : BaseDomainModel
{
public string? Name { get; set; }
public bool IsDeleted { get; set; }
public List<Team> Teams { get; set; } = new List<Team>() { };
}

View File

@ -61,6 +61,12 @@ Rollback to specific migration, use `list` command to see (Pending) changes:
To re-apply changes again, simply do a `database update` again. Beware that data will be lost.
When this error appears:
`Unable to create a 'DbContext' of type 'RuntimeType'. The exception 'The configuration file 'appsettings.json' was not found and is not optional.`
Then you should either provide an `appsettings.json` file in the project, or simply change the startup project.
## Links
* [Entity Framework - Database providers](https://learn.microsoft.com/en-us/ef/core/providers/?tabs=dotnet-core-cli)
@ -84,6 +90,24 @@ A list of installed NuGet packages in this application.
Note that the [Microsoft.EntityFrameworkCore.Tools](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/9.0.3) is used for Powershell commands used in the Package Manager Console for Visual Studio and that [Microsoft.EntityFrameworkCore.Design](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Design/9.0.3) is used for cross-platform command tools.
### API project
[Microsoft.VisualStudio.Web.CodeGeneration.Design](https://www.nuget.org/packages/Microsoft.VisualStudio.Web.CodeGeneration.Design/9.0.0)
* `dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design --version 9.0.0`
[Microsoft.EntityFrameworkCore.Design](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Design/9.0.3)
* `dotnet add package Microsoft.EntityFrameworkCore.Design --version 9.0.3`
[Microsoft.EntityFrameworkCore.Sqlite](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Sqlite/9.0.3)
* `dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 9.0.3`
[Microsoft.EntityFrameworkCore.Tools](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/9.0.3) *Required for aspnet-codegenerator cli tool.*
* `dotnet add package Microsoft.EntityFrameworkCore.Tools --version 9.0.3`
### Console project
[Microsoft.EntityFrameworkCore.Tools](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/9.0.3)
@ -100,6 +124,18 @@ Note that the [Microsoft.EntityFrameworkCore.Tools](https://www.nuget.org/packag
* `dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 9.0.3`
[Microsoft.Extensions.Configuration](https://www.nuget.org/packages/Microsoft.Extensions.Configuration/9.0.3)
* `dotnet add package Microsoft.Extensions.Configuration --version 9.0.3`
[Microsoft.Extensions.Configuration.FileExtensions](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.FileExtensions/9.0.3)
* `dotnet add package Microsoft.Extensions.Configuration.FileExtensions --version 9.0.3`
[Microsoft.Extensions.Configuration.Json](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.Json/9.0.3)
* `dotnet add package Microsoft.Extensions.Configuration.Json --version 9.0.3`
## Tips for efficient querying
* Use indexes.
@ -151,4 +187,39 @@ This is the least recommended method of loading data. It requires the [Microsoft
* A **Team** has one **Coach** (1:1)
* **Matches** are played by many **Teams** (M:M)
You can use [EF Core Power Tools](https://marketplace.visualstudio.com/items?itemName=ErikEJ.EFCorePowerTools) to create diagrams.
You can use [EF Core Power Tools](https://marketplace.visualstudio.com/items?itemName=ErikEJ.EFCorePowerTools) to create diagrams.
## ASP.NET Core with Entity Framework Core
A web application will make connection to the database on demand, which is a scoped connection. When not using the database, the web application is in a disconnected state.
You cannot create a new context in a file, because a new connection needs to be established every time and also closed, when the database is no longer needed. Also, *no tracking* is recommended, because multiple people can manipulate data.
An Inversion of Control (IoC) container will be used to handle dependancy injection for the DbContext. And also the DbContext will need a constructor with parameters to initialize itself properly.
## Scaffolding
### Scaffolding tool
[ASP.NET Core code generator tool](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/tools/dotnet-aspnet-codegenerator?view=aspnetcore-9.0).
* `dotnet tool install -g dotnet-aspnet-codegenerator` or, if already installed: `update`
To run this tool:
* `dotnet aspnet-codegenerator controller -name TeamsController -async -api -m Team -dc DeadBallZoneLeagueDbContext -outDir Controllers -dbProvider sqlite`
Note that an issue may arise, related to this: https://github.com/dotnet/Scaffolding/issues/3145
## API
Since .NET 9, the OpenAPI standard has been defined. To view documentation of our API, Swagger UI can be installed separately.
See also: https://devblogs.microsoft.com/dotnet/dotnet9-openapi/
* [https://swagger.io/tools/swagger-ui/](https://swagger.io/tools/swagger-ui/)
* [Swagger UI installation](https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/installation.md)
Or use:
* [install-swagger-tooling](https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-9.0&tabs=visual-studio-code#install-swagger-tooling)