Skip to content

Commit

Permalink
Merge branch 'dotnet7' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
christiannagel authored Nov 8, 2022
2 parents ab863f4 + 5ec3ded commit 98d9ed5
Show file tree
Hide file tree
Showing 9 changed files with 333 additions and 77 deletions.
4 changes: 2 additions & 2 deletions 1_CS/LINQ/EnumerableSample/EnumerableSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions 1_CS/LINQ/EnumerableSample/SortingSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

class SortingSamples
{
// .NET 7 update
public static void SortDefault()
{
Console.WriteLine("Sort all the racers by the default sort as implemented in the Racer type");
Console.WriteLine();

var racers = Formula1.GetChampions().Order().Take(10);

foreach (var racer in racers)
{
Console.WriteLine($"{racer.LastName}, {racer.FirstName}");
}
}

public static void SortMultiple()
{
Console.WriteLine("Show the first 10 champions ordered by country, lastname, firstname");
Expand Down
247 changes: 247 additions & 0 deletions 2_Libs/EFCore/Diagrams.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
# Diagrams

## Models


### Owned Entities

```mermaid
classDiagram
Address *-- Location : Location
Person *-- Address : BusinessAddress
Person o-- Address : PrivateAddress
class Location {
+Country: string
+City: string
}
class Address {
+LineOne: string
+LineTwo: string
}
class Person {
+PersonId: int
+FirstName: string
+LastName: string
}
```

```mermaid
erDiagram
People {
int PersonId
string FirstName
string LastName
string BusinessAdressLineOne
string BusinessAddressLineTwo
string BusinessCity
string BusinessCountry
int PrivateAddressId
}
PrivateAddresses {
string LineOne
string LineTwo
string City
string Country
}
```

### Table Splitting

```mermaid
classDiagram
MenuItem "1" o--> "1" MenuDetails : Details
class MenuDetails {
+MenuItemId: int
+KitchenInfo: string
+MenusSold: int
}
class MenuItem {
+MenuItemId: int
+Title: string
+Subtitle: string
+Price: decimal
}
```

```mermaid
erDiagram
MenuItem {
int MenuItemId
string Title
string Subtitle
money Price
string KitchenInfo
int MenusSold
}
```


##

```mermaid
classDiagram
MenuItem "1" o--> "1" MenuDetails : Details
class MenuDetails {
+MenuDetailsId: int
+KitchenInfo: string
+MenusSold: string
+Price: decimal
}
class MenuItem {
+MenuItemId: int
+Title: string
+Subtitle: string
+Price: decimal
}
class MenuCard {
+MenuCardId: int
+Title: string
}
class Restaurant {
+Name: string
}
```

## Inheritance

## Table per Hierarchy (TPH)

TPH is a pattern where you have a base class and multiple derived classes. Each derived class has its own table. The base class table contains a discriminator column that identifies the type of the derived class. The derived class tables contain all the columns of the base class table plus their own columns.

```mermaid
classDiagram
Payment <|-- CashPayment
Payment <|-- CreditcardPayment
class Payment {
+PaymentId: int
+Name: string
+Amount: decimal
}
class CashPayment {
}
class CreditcardPayment {
+CreditcardNumber: string
}
```

```mermaid
erDiagram
Payments {
int PaymentId
string PaymentType
string Name
money Amount
string CreditcardNumber
}
```

## Table per Type (TpT)

Table per type

```mermaid
erDiagram
Payments {
int PaymentId
string PaymentType
string Name
money Amount
}
CashPayments {
int PaymentId
}
CreditcardPayments {
int PaymentId
string CreditcardNumber
}
```

## Table per concrete Type (TcT)

```mermaid
classDiagram
Payment <|-- CashPayment
Payment <|-- CreditcardPayment
class Payment {
<<abstract>>
+PaymentId: int
+Name: string
+Amount: decimal
}
class CashPayment {
}
class CreditcardPayment {
+CreditcardNumber: string
}
```


```mermaid
erDiagram
CashPayments {
int PaymentId
string Name
money Amount
}
CreditcardPayments {
int PaymentId
string Name
money Amount
string CreditcardNumber
}
```

## Many-to-many Relationships

```mermaid
classDiagram
Book "*" <--> "*" Person
class Book {
+BookId: int
+Title: string
+Publisher: string
}
class Person {
+PersonId: int
+FirstName: string
+LastName: string
}
```

```mermaid
erDiagram
Books {
int BookId
string Title
string Publisher
}
People {
int PersonId
string FirstName
string LastName
}
BookPeople {
int BookId
int PersonId
}
```
22 changes: 9 additions & 13 deletions 3_Web/ASPNETCore/WebSampleApp/Extensions/HtmlExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text;

namespace WebSampleApp.Extensions;
namespace WebSampleApp.Extensions;

public static class HtmlExtensions
{
Expand All @@ -25,14 +23,12 @@ public static string Ul(this string value) =>
public static string HeadingX(this string value, int x) =>
$"<h{x}>{value}</h{x}>";

public static string HtmlDocument(this string content, string title)
{
StringBuilder sb = new();
sb.Append("<!DOCTYPE HTML>");
sb.Append($"<head><meta charset=\"utf-8\"><title>{title}</title></head>");
sb.Append("<body>");
sb.Append(content);
sb.Append("</body>");
return sb.ToString();
}
public static string HtmlDocument(this string content, string title) =>
$"""
<!DOCTYPE HTML>
<head><meta charset="utf-8"><title>{title}</title></head>
<body>
{content}
</body>
""";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace WebSampleApp.Middleware;

// You may need to install the Microsoft.AspNetCore.Http.Abstractions package into your project
public class HeaderMiddleware
{
private readonly RequestDelegate _next;
Expand Down
Loading

0 comments on commit 98d9ed5

Please sign in to comment.