Compare commits
4 Commits
e7e31f7f54
...
28e6e98e93
| Author | SHA1 | Date | |
|---|---|---|---|
| 28e6e98e93 | |||
| 3fae448287 | |||
| 5e688a24d5 | |||
| 62ae17f271 |
6
EntityFrameworkCore.Data/Class1.cs
Normal file
6
EntityFrameworkCore.Data/Class1.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace EntityFrameworkCore.Data;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
9
EntityFrameworkCore.Data/EntityFrameworkCore.Data.csproj
Normal file
9
EntityFrameworkCore.Data/EntityFrameworkCore.Data.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
6
EntityFrameworkCore.Domain/BaseDomainModel.cs
Normal file
6
EntityFrameworkCore.Domain/BaseDomainModel.cs
Normal 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;}
|
||||
}
|
||||
8
EntityFrameworkCore.Domain/Coach.cs
Normal file
8
EntityFrameworkCore.Domain/Coach.cs
Normal 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.
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
7
EntityFrameworkCore.Domain/Team.cs
Normal file
7
EntityFrameworkCore.Domain/Team.cs
Normal 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
34
README.md
Normal 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.
|
||||
14
ef-1.sln
14
ef-1.sln
@ -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
|
||||
VisualStudioVersion = 17.5.2.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "entity-framework", "entity-framework.csproj", "{F651371C-C6DF-B407-B9D0-5E6C224D4CD2}"
|
||||
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
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@ -7,4 +7,8 @@
|
||||
<RootNamespace>entity_framework</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user