Compare commits

...

4 Commits

Author SHA1 Message Date
28e6e98e93 Install NuGet package Entity Framework Core 9.0.3 version in solution. 2025-04-04 15:54:56 +02:00
3fae448287 Add initial README. 2025-04-04 15:54:24 +02:00
5e688a24d5 Add models for BaseDomainModel, Coach and Team. 2025-04-04 15:41:45 +02:00
62ae17f271 Create empty class libraries Data and Domain and add to solution.
dotnet new web
dotnet new classlib -o EntityFrameworkCore.Data
dotnet new classlib -o EntityFrameworkCore.Domain
dotnet sln add EntityFrameworkCore.Data/EntityFrameworkCore.Data.csproj
dotnet sln add EntityFrameworkCore.Domain/EntityFrameworkCore.Domain.csproj
2025-04-04 14:47:31 +02:00
9 changed files with 96 additions and 1 deletions

View File

@ -0,0 +1,6 @@
namespace EntityFrameworkCore.Data;
public class Class1
{
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,6 @@
namespace EntityFrameworkCore.Domain;
// Since C#11, you do not need to wrap in accolades anymore.
public abstract class BaseDomainModel
{
public DateTime CreatedDate { get; set;}
}

View File

@ -0,0 +1,8 @@
namespace EntityFrameworkCore.Domain;
// Since C#11, you do not need to wrap in accolades anymore.
public class Coach : BaseDomainModel
{
public int Id { get; set; } // Anything called "Id" is automatically a Primary Key.
public string Name { get; set; } // Strings are automatically become VARCHAR database types.
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,7 @@
namespace EntityFrameworkCore.Domain;
// Since C#11, you do not need to wrap in accolades anymore.
public class Team : BaseDomainModel
{
public int TeamId { get; set;} // This naming convention also allows EF to see this as a PK.
public string? Name { get; set; }
}

34
README.md Normal file
View File

@ -0,0 +1,34 @@
# Entity Framework - Dead Ball Zone
This is a practice project to learn Entity Framework.
Using the 1998 game [Dead Ball Zone](https://en.wikipedia.org/wiki/Dead_Ball_Zone) for inspiration.
## .NET commands:
### NuGet commands
Install [Entity Framework Core NuGet package](https://www.nuget.org/packages/microsoft.entityframeworkcore):
`dotnet add package Microsoft.EntityFrameworkCore --version 9.0.3`
### Creation commands
To list all available templates:
`dotnet new -l`
New class:
`dotnet new class -n MyClass`
adding to an existing solution:
`dotnet sln add Data/Data.csproj`
## Terms
A **database-context** is an abstraction of the database structure in code.
* It lists the models and their database table names.
* It instantiates a database connection during the runtime of the application.
* Allows configurations to be made in code.

View File

@ -1,9 +1,13 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.5.2.0 VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "entity-framework", "entity-framework.csproj", "{F651371C-C6DF-B407-B9D0-5E6C224D4CD2}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "entity-framework", "entity-framework.csproj", "{F651371C-C6DF-B407-B9D0-5E6C224D4CD2}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.Data", "EntityFrameworkCore.Data\EntityFrameworkCore.Data.csproj", "{EB2B89D9-FE82-47CC-877F-223A4CA1755E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.Domain", "EntityFrameworkCore.Domain\EntityFrameworkCore.Domain.csproj", "{DC955178-72C3-4574-86DE-1D966E38780E}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -14,6 +18,14 @@ Global
{F651371C-C6DF-B407-B9D0-5E6C224D4CD2}.Debug|Any CPU.Build.0 = Debug|Any CPU {F651371C-C6DF-B407-B9D0-5E6C224D4CD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F651371C-C6DF-B407-B9D0-5E6C224D4CD2}.Release|Any CPU.ActiveCfg = Release|Any CPU {F651371C-C6DF-B407-B9D0-5E6C224D4CD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F651371C-C6DF-B407-B9D0-5E6C224D4CD2}.Release|Any CPU.Build.0 = Release|Any CPU {F651371C-C6DF-B407-B9D0-5E6C224D4CD2}.Release|Any CPU.Build.0 = Release|Any CPU
{EB2B89D9-FE82-47CC-877F-223A4CA1755E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB2B89D9-FE82-47CC-877F-223A4CA1755E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB2B89D9-FE82-47CC-877F-223A4CA1755E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB2B89D9-FE82-47CC-877F-223A4CA1755E}.Release|Any CPU.Build.0 = Release|Any CPU
{DC955178-72C3-4574-86DE-1D966E38780E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC955178-72C3-4574-86DE-1D966E38780E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC955178-72C3-4574-86DE-1D966E38780E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC955178-72C3-4574-86DE-1D966E38780E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -7,4 +7,8 @@
<RootNamespace>entity_framework</RootNamespace> <RootNamespace>entity_framework</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
</ItemGroup>
</Project> </Project>