Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 1_CS/LINQ/DataLib/DataLib.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
109 changes: 56 additions & 53 deletions 1_CS/LINQ/DataLib/Formula1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,47 @@ public static class Formula1
private static List<Racer>? s_racers;
public static IList<Racer> GetChampions() => s_racers ??= InitializeRacers();

private static List<Racer> InitializeRacers() => new()
{
new("Nino", "Farina", "Italy", 33, 5, new[] { 1950 }, new[] { "Alfa Romeo" }),
new("Alberto", "Ascari", "Italy", 32, 13, new[] { 1952, 1953 }, new[] { "Ferrari" }),
new("Juan Manuel", "Fangio", "Argentina", 51, 24, new int[] { 1951, 1954, 1955, 1956, 1957 }, new string[] { "Alfa Romeo", "Maserati", "Mercedes", "Ferrari" }),
new("Mike", "Hawthorn", "UK", 45, 3, new int[] { 1958 }, new string[] { "Ferrari" }),
new("Phil", "Hill", "USA", 48, 3, new int[] { 1961 }, new string[] { "Ferrari" }),
new("John", "Surtees", "UK", 111, 6, new int[] { 1964 }, new string[] { "Ferrari" }),
new("Jim", "Clark", "UK", 72, 25, new int[] { 1963, 1965 }, new string[] { "Lotus" }),
new("Jack", "Brabham", "Australia", 125, 14, new int[] { 1959, 1960, 1966 }, new string[] { "Cooper", "Brabham" }),
new("Denny", "Hulme", "New Zealand", 112, 8, new int[] { 1967 }, new string[] { "Brabham" }),
new("Graham", "Hill", "UK", 176, 14, new int[] { 1962, 1968 }, new string[] { "BRM", "Lotus" }),
new("Jochen", "Rindt", "Austria", 60, 6, new int[] { 1970 }, new string[] { "Lotus" }),
new("Jackie", "Stewart", "UK", 99, 27, new int[] { 1969, 1971, 1973 }, new string[] { "Matra", "Tyrrell" }),
new("Emerson", "Fittipaldi", "Brazil", 144, 14, new int[] { 1972, 1974 }, new string[] { "Lotus", "McLaren" }),
new("James", "Hunt", "UK", 92, 10, new int[] { 1976 }, new string[] { "McLaren" }),
new("Mario", "Andretti", "USA", 128, 12, new int[] { 1978 }, new string[] { "Lotus" }),
new("Jody", "Scheckter", "South Africa", 112, 10, new int[] { 1979 }, new string[] { "Ferrari" }),
new("Alan", "Jones", "Australia", 116, 12, new int[] { 1980 }, new string[] { "Williams" }),
new("Keke", "Rosberg", "Finland", 114, 5, new int[] { 1982 }, new string[] { "Williams" }),
new("Niki", "Lauda", "Austria", 171, 25, new int[] { 1975, 1977, 1984 }, new string[] { "Ferrari", "McLaren" }),
new("Nelson", "Piquet", "Brazil", 204, 23, new int[] { 1981, 1983, 1987 }, new string[] { "Brabham", "Williams" }),
new("Ayrton", "Senna", "Brazil", 161, 41, new int[] { 1988, 1990, 1991 }, new string[] { "McLaren" }),
new("Nigel", "Mansell", "UK", 187, 31, new int[] { 1992 }, new string[] { "Williams" }),
new("Alain", "Prost", "France", 199, 51, new int[] { 1985, 1986, 1989, 1993 }, new string[] { "McLaren", "Williams" }),
new("Damon", "Hill", "UK", 115, 22, new int[] { 1996 }, new string[] { "Williams" }),
new("Jacques", "Villeneuve", "Canada", 163, 11, new int[] { 1997 }, new string[] { "Williams" }),
new("Mika", "Hakkinen", "Finland", 161, 20, new int[] { 1998, 1999 }, new string[] { "McLaren" }),
new("Michael", "Schumacher", "Germany", 306, 91, new int[] { 1994, 1995, 2000, 2001, 2002, 2003, 2004 }, new string[] { "Benetton", "Ferrari" }),
new("Fernando", "Alonso", "Spain", 370, 32, new int[] { 2005, 2006 }, new string[] { "Renault" }),
new("Kimi", "Räikkönen", "Finland", 349, 21, new int[] { 2007 }, new string[] { "Ferrari" }),
new("Jenson", "Button", "UK", 306, 16, new int[] { 2009 }, new string[] { "Brawn GP" }),
new("Sebastian", "Vettel", "Germany", 299, 53, new int[] { 2010, 2011, 2012, 2013 }, new string[] { "Red Bull Racing" }),
new("Nico", "Rosberg", "Germany", 206, 24, new int[] { 2016 }, new string[] { "Mercedes" }),
new("Lewis", "Hamilton", "UK", 322, 103, new int[] { 2008, 2014, 2015, 2017, 2018, 2019, 2020 }, new string[] { "McLaren", "Mercedes" }),
new("Max", "Verstappen", "Netherlands", 175, 45, new int[] { 2021, 2022 }, new string[] { "Red Bull Racing" })
};
private static List<Racer> InitializeRacers() =>
[
new("Nino", "Farina", "Italy", 33, 5, [1950], ["Alfa Romeo"]),
new("Alberto", "Ascari", "Italy", 32, 13, [1952, 1953], ["Ferrari"]),
new("Juan Manuel", "Fangio", "Argentina", 51, 24, [1951, 1954, 1955, 1956, 1957], ["Alfa Romeo", "Maserati", "Mercedes", "Ferrari"]),
new("Mike", "Hawthorn", "UK", 45, 3, [1958], ["Ferrari"]),
new("Phil", "Hill", "USA", 48, 3, [1961], ["Ferrari"]),
new("John", "Surtees", "UK", 111, 6, [1964], ["Ferrari"]),
new("Jim", "Clark", "UK", 72, 25, [1963, 1965], ["Lotus"]),
new("Jack", "Brabham", "Australia", 125, 14, [1959, 1960, 1966], ["Cooper", "Brabham"]),
new("Denny", "Hulme", "New Zealand", 112, 8, [1967], ["Brabham"]),
new("Graham", "Hill", "UK", 176, 14, [1962, 1968], ["BRM", "Lotus"]),
new("Jochen", "Rindt", "Austria", 60, 6, [1970], ["Lotus"]),
new("Jackie", "Stewart", "UK", 99, 27, [1969, 1971, 1973], ["Matra", "Tyrrell"]),
new("Emerson", "Fittipaldi", "Brazil", 144, 14, [1972, 1974], ["Lotus", "McLaren"]),
new("James", "Hunt", "UK", 92, 10, [1976], ["McLaren"]),
new("Mario", "Andretti", "USA", 128, 12, [1978], ["Lotus"]),
new("Jody", "Scheckter", "South Africa", 112, 10, [1979], ["Ferrari"]),
new("Alan", "Jones", "Australia", 116, 12, [1980], ["Williams"]),
new("Keke", "Rosberg", "Finland", 114, 5, [1982], ["Williams"]),
new("Niki", "Lauda", "Austria", 171, 25, [1975, 1977, 1984], ["Ferrari", "McLaren"]),
new("Nelson", "Piquet", "Brazil", 204, 23, [1981, 1983, 1987], ["Brabham", "Williams"]),
new("Ayrton", "Senna", "Brazil", 161, 41, [1988, 1990, 1991], ["McLaren"]),
new("Nigel", "Mansell", "UK", 187, 31, [1992], ["Williams"]),
new("Alain", "Prost", "France", 199, 51, [1985, 1986, 1989, 1993], ["McLaren", "Williams"]),
new("Damon", "Hill", "UK", 115, 22, [1996], ["Williams"]),
new("Jacques", "Villeneuve", "Canada", 163, 11, [1997], ["Williams"]),
new("Mika", "Hakkinen", "Finland", 161, 20, [1998, 1999], ["McLaren"]),
new("Michael", "Schumacher", "Germany", 306, 91, [1994, 1995, 2000, 2001, 2002, 2003, 2004], ["Benetton", "Ferrari"]),
new("Fernando", "Alonso", "Spain", 404, 32, [2005, 2006], ["Renault"]),
new("Kimi", "Räikkönen", "Finland", 349, 21, [2007], ["Ferrari"]),
new("Jenson", "Button", "UK", 306, 16, [2009], ["Brawn GP"]),
new("Sebastian", "Vettel", "Germany", 299, 53, [2010, 2011, 2012, 2013], ["Red Bull Racing"]),
new("Nico", "Rosberg", "Germany", 206, 24, [2016], ["Mercedes"]),
new("Lewis", "Hamilton", "UK", 335, 105, [2008, 2014, 2015, 2017, 2018, 2019, 2020], ["McLaren", "Mercedes"]),
new("Max", "Verstappen", "Netherlands", 209, 63, [2021, 2022, 2023, 2024], ["Red Bull Racing"])
];

private static List<Team>? s_teams;
public static IList<Team> GetConstructorChampions() => s_teams ??= new()
{
public static IList<Team> GetConstructorChampions() => s_teams ??=
[
new("Vanwall", 1958),
new("Cooper", 1959, 1960),
new("BRM", 1962),
Expand All @@ -55,17 +55,17 @@ public static class Formula1
new("Lotus", 1963, 1965, 1968, 1970, 1972, 1973, 1978),
new("Benetton", 1995),
new("Williams", 1980, 1981, 1986, 1987, 1992, 1993, 1994, 1996, 1997),
new("McLaren", 1974, 1984, 1985, 1988, 1989, 1990, 1991, 1998),
new("McLaren", 1974, 1984, 1985, 1988, 1989, 1990, 1991, 1998, 2024),
new("Renault", 2005, 2006),
new("Ferrari", 1961, 1964, 1975, 1976, 1977, 1979, 1982, 1983, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2008),
new("Brawn GP", 2009),
new("Red Bull Racing", 2010, 2011, 2012, 2013, 2022),
new("Red Bull Racing", 2010, 2011, 2012, 2013, 2022, 2023),
new("Mercedes", 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021)
};
];

private static List<Championship>? s_championships;
public static IEnumerable<Championship> GetChampionships() => s_championships ??= new()
{
public static IEnumerable<Championship> GetChampionships() => s_championships ??=
[
new(1950, "Nino Farina", "Juan Manuel Fangio", "Luigi Fagioli"),
new(1951, "Juan Manuel Fangio", "Alberto Ascari", "Froilan Gonzalez"),
new(1952, "Alberto Ascari", "Nino Farina", "Piero Taruffi"),
Expand Down Expand Up @@ -139,11 +139,13 @@ public static class Formula1
new(2020, "Lewis Hamilton", "Valtteri Bottas", "Max Verstappen"),
new(2021, "Max Verstappen", "Lewis Hamilton", "Valtteri Bottas"),
new(2022, "Max Verstappen", "Charles Leclerc","Sergio Perez"),
};
new Championship(2023, "Max Verstappen", "Sergio Perez", "Lewis Hamilton"),
new Championship(2024, "Max Verstappen", "Lando Norris", "Charles Leclerc")
];

private static List<Racer>? s_moreRacers;
public static IList<Racer> GetMoreRacers() => s_moreRacers ??= new()
{
public static IList<Racer> GetMoreRacers() => s_moreRacers ??=
[
new Racer("Luigi", "Fagioli", "Italy", Starts: 7, Wins: 1),
new Racer("Jose Froilan", "Gonzalez", "Argentina", 26, 2),
new Racer("Piero", "Taruffi", "Italy", Starts: 18, Wins: 1),
Expand Down Expand Up @@ -175,9 +177,10 @@ public static class Formula1
new Racer("Juan Pablo", "Montoya", "Columbia", Starts: 94, Wins: 7),
new Racer("Felipe", "Massa", "Brazil", Starts: 269, Wins: 11),
new Racer("Mark", "Webber", "Australia", Starts: 215, Wins: 9),
new Racer("Daniel", "Ricciardo", "Australia", Starts: 234, Wins: 8),
new Racer("Valtteri", "Bottas", "Finland", Starts: 212, Wins: 10),
new Racer("Charles", "Leclerc", "Monaco", Starts: 115, Wins: 5),
new Racer("Sergio", "Perez", "Mexico", Starts: 248, Wins: 6),
};
}
new Racer("Daniel", "Ricciardo", "Australia", Starts: 257, Wins: 8),
new Racer("Valtteri", "Bottas", "Finland", Starts: 246, Wins: 10),
new Racer("Charles", "Leclerc", "Monaco", Starts: 149, Wins: 8),
new Racer("Sergio", "Perez", "Mexico", Starts: 282, Wins: 6),
new Racer("Lando", "Norris", "UK", Starts: 128, Wins: 4)
];
}
2 changes: 1 addition & 1 deletion 1_CS/LINQ/DataLib/Racer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public record Racer(string FirstName, string LastName, string Country, int Starts, int Wins, IEnumerable<int> Years, IEnumerable<string> Cars) : IComparable<Racer>, IFormattable
{
public Racer(string FirstName, string LastName, string Country, int Starts, int Wins)
: this(FirstName, LastName, Country, Starts, Wins, new int[] { }, new string[] { })
: this(FirstName, LastName, Country, Starts, Wins, [], [])
{ }

public override string ToString() => $"{FirstName} {LastName}";
Expand Down
2 changes: 1 addition & 1 deletion 1_CS/LINQ/DataLib/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public record Team
public Team(string name, params int[] years)
{
Name = name;
Years = years is not null ? new List<int>(years) : new List<int>();
Years = years is not null ? [.. years] : [];
}
public string Name { get; }
public IEnumerable<int> Years { get; }
Expand Down
2 changes: 1 addition & 1 deletion 1_CS/LINQ/EnumerableSample/EnumerableSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion 1_CS/LINQ/ExpressionTreeSample/ExpressionTreeSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion 1_CS/LINQ/LinqIntro/LinqIntro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion 1_CS/LINQ/ParallelLinqSample/ParallelLinqSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
14 changes: 4 additions & 10 deletions 2_Libs/EFCore/BooksLib/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@

namespace BooksLib;

public class Book
public class Book(string title, string? publisher = default, int bookId = default)
{
public Book(string title, string? publisher = default, int bookId = default)
{
Title = title;
Publisher = publisher;
BookId = bookId;
}
[StringLength(50)]
public string Title { get; set; }
public string Title { get; set; } = title;
[StringLength(30)]
public string? Publisher { get; set; }
public int BookId { get; set; }
public string? Publisher { get; set; } = publisher;
public int BookId { get; set; } = bookId;
[StringLength(20)]
public string? Isbn { get; set; }
}
5 changes: 1 addition & 4 deletions 2_Libs/EFCore/BooksLib/BooksContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace BooksLib;

public class BooksContext : DbContext
public class BooksContext(DbContextOptions<BooksContext> options) : DbContext(options)
{
public BooksContext(DbContextOptions<BooksContext> options)
: base(options) { }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
Expand Down
6 changes: 3 additions & 3 deletions 2_Libs/EFCore/BooksLib/BooksLib.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>


Expand Down
15 changes: 5 additions & 10 deletions 2_Libs/EFCore/ConflictHandling-FirstWins/Book.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
using System.ComponentModel.DataAnnotations;
namespace ConfictHandling;

public class Book
public class Book(string title, string? publisher = default, int bookId = default)
{
public Book(string title, string? publisher = default, int bookId = default)
{
Title = title;
Publisher = publisher;
BookId = bookId;
}
[StringLength(50)]
public string Title { get; set; }
public string Title { get; set; } = title;
[StringLength(30)]
public string? Publisher { get; set; }
public int BookId { get; set; }
public string? Publisher { get; set; } = publisher;
public int BookId { get; set; } = bookId;
}
9 changes: 3 additions & 6 deletions 2_Libs/EFCore/ConflictHandling-FirstWins/BooksContext.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Microsoft.EntityFrameworkCore;
namespace ConfictHandling;

public class BooksContext : DbContext
public class BooksContext(DbContextOptions<BooksContext> options) : DbContext(options)
{
public BooksContext(DbContextOptions<BooksContext> options)
: base(options) { }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var sampleBooks = GetSampleBooks();
Expand All @@ -16,7 +13,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.IsRowVersion();
}

private IEnumerable<Book> GetSampleBooks()
private static IEnumerable<Book> GetSampleBooks()
=> Enumerable.Range(1, 100)
.Select(id => new Book($"title {id}", "sample", id)).ToArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand All @@ -12,13 +12,13 @@
</PropertyGroup>-->

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 7 additions & 0 deletions 2_Libs/EFCore/ConflictHandling-FirstWins/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
global using ConfictHandling;

global using Microsoft.EntityFrameworkCore;
global using Microsoft.EntityFrameworkCore.ChangeTracking;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Hosting;
14 changes: 4 additions & 10 deletions 2_Libs/EFCore/ConflictHandling-FirstWins/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;


using var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
var connectionString = context.Configuration.GetConnectionString("BooksConnection");
services.AddDbContext<BooksContext>(options =>
{
options.UseSqlServer(connectionString);
});
string connectionString = context.Configuration.GetConnectionString("BooksConnection") ?? throw new InvalidOperationException("Could not read BooksConnection");
services.AddDbContext<BooksContext>(options =>
options.UseSqlServer(connectionString));
services.AddScoped<Runner>();
})
.Build();
Expand Down
Loading
Loading