Skip to content

Commit ef91a5b

Browse files
Merge branch 'dotnet6' into winappsdk1.0
2 parents fbb27d9 + 6cea57d commit ef91a5b

File tree

320 files changed

+66283
-40398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

320 files changed

+66283
-40398
lines changed

1_CS/HelloWorld/Readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
This chapter contains the following code samples:
66

77
* HelloWorld (.NET Core Console App)
8-
* WebApp (Tool-generated ASP.NET Core MVC Web App)
8+
* WebApp (Tool-generated ASP.NET Core Web App)
99
* SelfContainedHelloWorld (Console App configured for self-contained deployment)
1010
* TrimmedHelloWorld
1111

1_CS/LINQ/DataLib/Formula1.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace DataLib;
1+
namespace DataLib;
22

33
public static class Formula1
44
{
@@ -34,12 +34,13 @@ public static class Formula1
3434
new("Jacques", "Villeneuve", "Canada", 165, 11, new int[] { 1997 }, new string[] { "Williams" }),
3535
new("Mika", "Hakkinen", "Finland", 160, 20, new int[] { 1998, 1999 }, new string[] { "McLaren" }),
3636
new("Michael", "Schumacher", "Germany", 287, 91, new int[] { 1994, 1995, 2000, 2001, 2002, 2003, 2004 }, new string[] { "Benetton", "Ferrari" }),
37-
new("Fernando", "Alonso", "Spain", 335, 32, new int[] { 2005, 2006 }, new string[] { "Renault" }),
38-
new("Kimi", "Räikkönen", "Finland", 351, 21, new int[] { 2007 }, new string[] { "Ferrari" }),
37+
new("Fernando", "Alonso", "Spain", 336, 32, new int[] { 2005, 2006 }, new string[] { "Renault" }),
38+
new("Kimi", "Räikkönen", "Finland", 352, 21, new int[] { 2007 }, new string[] { "Ferrari" }),
3939
new("Jenson", "Button", "UK", 306, 16, new int[] { 2009 }, new string[] { "Brawn GP" }),
40-
new("Sebastian", "Vettel", "Germany", 278, 53, new int[] { 2010, 2011, 2012, 2013 }, new string[] { "Red Bull Racing" }),
40+
new("Sebastian", "Vettel", "Germany", 280, 53, new int[] { 2010, 2011, 2012, 2013 }, new string[] { "Red Bull Racing" }),
4141
new("Nico", "Rosberg", "Germany", 207, 24, new int[] { 2016 }, new string[] { "Mercedes" }),
42-
new("Lewis", "Hamilton", "UK", 286, 102, new int[] { 2008, 2014, 2015, 2017, 2018, 2019, 2020 }, new string[] { "McLaren", "Mercedes" }),
42+
new("Lewis", "Hamilton", "UK", 288, 103, new int[] { 2008, 2014, 2015, 2017, 2018, 2019, 2020 }, new string[] { "McLaren", "Mercedes" }),
43+
new("Max", "Verstappen", "Netherlands", 141, 20, new int[] { 2021 }, new string[] { "Red Bull Racing" })
4344
};
4445

4546
private static List<Team>? s_teams;
@@ -59,10 +60,9 @@ public static class Formula1
5960
new("Ferrari", 1961, 1964, 1975, 1976, 1977, 1979, 1982, 1983, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2008),
6061
new("Brawn GP", 2009),
6162
new("Red Bull Racing", 2010, 2011, 2012, 2013),
62-
new("Mercedes", 2014, 2015, 2016, 2017, 2018, 2019, 2020)
63+
new("Mercedes", 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021)
6364
};
6465

65-
6666
private static List<Championship>? s_championships;
6767
public static IEnumerable<Championship> GetChampionships() => s_championships ??= new()
6868
{
@@ -136,7 +136,8 @@ public static class Formula1
136136
new(2017, "Lewis Hamilton", "Sebastian Vettel", "Valtteri Bottas"),
137137
new(2018, "Lewis Hamilton", "Sebastian Vettel", "Kimi Räikkönen"),
138138
new(2019, "Lewis Hamilton", "Valtteri Bottas", "Max Verstappen"),
139-
new(2020, "Lewis Hamilton", "Valtteri Bottas", "Max Verstappen")
139+
new(2020, "Lewis Hamilton", "Valtteri Bottas", "Max Verstappen"),
140+
new(2021, "Max Verstappen", "Lewis Hamilton", "Valtteri Bottas")
140141
};
141142

142143
private static List<Racer>? _moreRacers;
@@ -173,8 +174,7 @@ public static class Formula1
173174
new Racer("Juan Pablo", "Montoya", "Columbia", Starts: 94, Wins: 7),
174175
new Racer("Felipe", "Massa", "Brazil", Starts: 269, Wins: 11),
175176
new Racer("Mark", "Webber", "Australia", Starts: 215, Wins: 9),
176-
new Racer("Daniel", "Ricciardo", "Australia", Starts: 208, Wins: 8),
177-
new Racer("Valtteri", "Bottas", "Finland", Starts: 176, Wins: 10),
178-
new Racer("Max", "Verstappen", "Netherlands", Starts: 139, Wins: 19)
177+
new Racer("Daniel", "Ricciardo", "Australia", Starts: 210, Wins: 8),
178+
new Racer("Valtteri", "Bottas", "Finland", Starts: 178, Wins: 10)
179179
};
180180
}

2_Libs/EFCore/BooksLib/Book.cs

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
using System.ComponentModel.DataAnnotations;
22

3-
namespace BooksLib
3+
namespace BooksLib;
4+
5+
public class Book
46
{
5-
public class Book
7+
public Book(string title, string? publisher = default, int bookId = default)
68
{
7-
public Book(string title, string? publisher = default, int bookId = default)
8-
{
9-
Title = title;
10-
Publisher = publisher;
11-
BookId = bookId;
12-
}
13-
[StringLength(50)]
14-
public string Title { get; set; }
15-
[StringLength(30)]
16-
public string? Publisher { get; set; }
17-
public int BookId { get; set; }
18-
[StringLength(20)]
19-
public string? Isbn { get; set; }
9+
Title = title;
10+
Publisher = publisher;
11+
BookId = bookId;
2012
}
21-
22-
}
13+
[StringLength(50)]
14+
public string Title { get; set; }
15+
[StringLength(30)]
16+
public string? Publisher { get; set; }
17+
public int BookId { get; set; }
18+
[StringLength(20)]
19+
public string? Isbn { get; set; }
20+
}
+9-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
using Microsoft.EntityFrameworkCore;
22

3-
namespace BooksLib
3+
namespace BooksLib;
4+
5+
public class BooksContext : DbContext
46
{
7+
public BooksContext(DbContextOptions<BooksContext> options)
8+
: base(options) { }
59

6-
public class BooksContext : DbContext
10+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
711
{
8-
public BooksContext(DbContextOptions<BooksContext> options)
9-
: base(options) { }
10-
11-
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
12-
{
13-
base.OnConfiguring(optionsBuilder);
14-
}
15-
16-
public DbSet<Book> Books => Set<Book>();
12+
base.OnConfiguring(optionsBuilder);
1713
}
14+
15+
public DbSet<Book> Books => Set<Book>();
1816
}

2_Libs/EFCore/BooksLib/BooksLib.csproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
67
</PropertyGroup>
78

89
<ItemGroup>
9-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" />
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.5" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
1112
</ItemGroup>
1213

1314

2_Libs/EFCore/ConflictHandling-FirstWins/BooksContext.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using Microsoft.EntityFrameworkCore;
2-
using System.Collections.Generic;
3-
using System.Linq;
42

53
public class BooksContext : DbContext
64
{

2_Libs/EFCore/ConflictHandling-FirstWins/ConflictHandling-FirstWins.csproj

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
78
</PropertyGroup>
89

910
<!--<PropertyGroup>
1011
<DefineConstants>USERECORDS</DefineConstants>
1112
</PropertyGroup>-->
1213

1314
<ItemGroup>
14-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" />
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5">
15+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
1617
<PrivateAssets>all</PrivateAssets>
1718
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1819
</PackageReference>
19-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.5" />
20-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
20+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
21+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
2122
</ItemGroup>
2223

2324
<ItemGroup>

2_Libs/EFCore/ConflictHandling-FirstWins/Program.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Microsoft.Extensions.Configuration;
33
using Microsoft.Extensions.DependencyInjection;
44
using Microsoft.Extensions.Hosting;
5-
using System;
65

76
using var host = Host.CreateDefaultBuilder(args)
87
.ConfigureServices((context, services) =>
@@ -24,8 +23,8 @@
2423
}
2524

2625
// different scopes for the users and prepare update
27-
using var user1Scope = host.Services.CreateScope();
28-
using var user2Scope = host.Services.CreateScope();
26+
await using var user1Scope = host.Services.CreateAsyncScope();
27+
await using var user2Scope = host.Services.CreateAsyncScope();
2928
var user1Runner = user1Scope.ServiceProvider.GetRequiredService<Runner>();
3029
var user2Runner = user2Scope.ServiceProvider.GetRequiredService<Runner>();
3130
int bookId = await user1Runner.PrepareUpdateAsync("user1");
@@ -36,7 +35,7 @@
3635
await user2Runner.UpdateAsync();
3736

3837
// check for the winner
39-
using var checkScope = host.Services.CreateScope();
38+
await using var checkScope = host.Services.CreateAsyncScope();
4039
var runner = checkScope.ServiceProvider.GetRequiredService<Runner>();
4140
string updatedTitle = await runner.GetUpdatedTitleAsyc(bookId);
4241
Console.Write("this is the winner: ");

2_Libs/EFCore/ConflictHandling-FirstWins/Runner.cs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using Microsoft.EntityFrameworkCore;
22
using Microsoft.EntityFrameworkCore.ChangeTracking;
3-
using System;
4-
using System.Linq;
5-
using System.Threading.Tasks;
63

74
public class Runner
85
{
@@ -64,7 +61,7 @@ public async Task UpdateAsync()
6461
if (entry.Entity is Book b)
6562
{
6663
PropertyEntry pe = entry.Property("Timestamp");
67-
Console.WriteLine($"{b.Title} {BitConverter.ToString((byte[])pe.CurrentValue)}");
64+
Console.WriteLine($"{b.Title} {pe.TimestampToString()}");
6865
ShowChanges(_selectedBook.BookId, _booksContext.Entry(_selectedBook));
6966
}
7067
}
@@ -85,6 +82,17 @@ static void ShowChange(PropertyEntry propertyEntry, int id) =>
8582
public async Task<string> GetUpdatedTitleAsyc(int id)
8683
{
8784
var book = await _booksContext.Books.FindAsync(id);
85+
if (book is null) return string.Empty;
8886
return $"{book.Title} with id {book.BookId}";
8987
}
9088
}
89+
90+
internal static class Converter
91+
{
92+
public static string TimestampToString(this PropertyEntry entry)
93+
{
94+
if (entry.CurrentValue is null) return string.Empty;
95+
byte[] data = (byte[])entry.CurrentValue;
96+
return BitConverter.ToString(data);
97+
}
98+
}

2_Libs/EFCore/ConflictHandling-LastWins/BooksContext.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using Microsoft.EntityFrameworkCore;
2-
using System.Collections.Generic;
3-
using System.Linq;
42

53
public class BooksContext : DbContext
64
{

2_Libs/EFCore/ConflictHandling-LastWins/ConflictHandling-LastWins.csproj

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
78
</PropertyGroup>
89

910
<!--<PropertyGroup>
1011
<DefineConstants>USERECORDS</DefineConstants>
1112
</PropertyGroup>-->
1213

1314
<ItemGroup>
14-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" />
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5">
15+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
1617
<PrivateAssets>all</PrivateAssets>
1718
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1819
</PackageReference>
19-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.5" />
20-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
20+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
21+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
2122
</ItemGroup>
2223

2324
<ItemGroup>

2_Libs/EFCore/ConflictHandling-LastWins/Program.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Microsoft.Extensions.Configuration;
33
using Microsoft.Extensions.DependencyInjection;
44
using Microsoft.Extensions.Hosting;
5-
using System;
65

76
using var host = Host.CreateDefaultBuilder(args)
87
.ConfigureServices((context, services) =>
@@ -16,22 +15,22 @@
1615
})
1716
.Build();
1817

19-
using (var scope = host.Services.CreateScope())
18+
await using (var scope = host.Services.CreateAsyncScope())
2019
{
2120
var creator = scope.ServiceProvider.GetRequiredService<Runner>();
2221
await creator.CreateTheDatabaseAsync();
2322
}
2423

25-
using var user1Scope = host.Services.CreateScope();
26-
using var user2Scope = host.Services.CreateScope();
24+
await using var user1Scope = host.Services.CreateAsyncScope();
25+
await using var user2Scope = host.Services.CreateAsyncScope();
2726
var user1Runner = user1Scope.ServiceProvider.GetRequiredService<Runner>();
2827
var user2Runner = user2Scope.ServiceProvider.GetRequiredService<Runner>();
2928
int bookId = await user1Runner.PrepareUpdateAsync("user1");
3029
await user2Runner.PrepareUpdateAsync("user2", bookId);
3130
await user1Runner.UpdateAsync();
3231
await user2Runner.UpdateAsync();
3332

34-
using var checkScope = host.Services.CreateScope();
33+
await using var checkScope = host.Services.CreateAsyncScope();
3534
var runner = checkScope.ServiceProvider.GetRequiredService<Runner>();
3635
string updatedTitle = await runner.GetUpdatedTitleAsyc(bookId);
3736
Console.Write("this is the winner: ");

2_Libs/EFCore/ConflictHandling-LastWins/Runner.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading;
5-
using System.Threading.Tasks;
6-
using Microsoft.EntityFrameworkCore;
1+
using Microsoft.EntityFrameworkCore;
72

83
public class Runner
94
{
@@ -60,6 +55,7 @@ public async Task UpdateAsync()
6055
public async Task<string> GetUpdatedTitleAsyc(int id)
6156
{
6257
var book = await _booksContext.Books.FindAsync(id);
58+
if (book is null) return String.Empty;
6359
return $"{book.Title} with id {book.BookId}";
6460
}
6561
}

2_Libs/EFCore/Cosmos/Cosmos.csproj

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
78
<UserSecretsId>6a71cc89-6908-4ebf-81da-6c43fdc7f321</UserSecretsId>
89
</PropertyGroup>
910

1011
<ItemGroup>
11-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" />
12-
<PackageReference Include="Microsoft.EntityFrameworkCore.Cosmos" Version="5.0.5" />
13-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5">
12+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.Cosmos" Version="6.0.0" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
1415
<PrivateAssets>all</PrivateAssets>
1516
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1617
</PackageReference>
17-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="5.0.0" />
18-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
1920
</ItemGroup>
2021

2122
<ItemGroup>

2_Libs/EFCore/Cosmos/MenuCard.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
4-
public class MenuCard
1+
public class MenuCard
52
{
63
public MenuCard(string title, string restaurantId, Guid menuCardId = default)
74
=> (Title, RestaurantId, MenuCardId) = (title, restaurantId, menuCardId);

2_Libs/EFCore/Cosmos/MenuItem.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
3-
public class MenuItem
1+
public class MenuItem
42
{
53
public MenuItem(string text, Guid menuItemId = default) => (Text, MenuItemId) = (text, menuItemId);
64

2_Libs/EFCore/Cosmos/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
})
1919
.Build();
2020

21-
using var scope = host.Services.CreateScope();
21+
await using var scope = host.Services.CreateAsyncScope();
2222
var runner = scope.ServiceProvider.GetRequiredService<Runner>();
2323
await runner.CreateDatabaseAsync();
2424

0 commit comments

Comments
 (0)