Commit c2b71ee2 authored by Andres Käver's avatar Andres Käver
Browse files

db demo, slides

parent fc6e2bd3
# Common IntelliJ Platform excludes
.idea/
*.suo
*.user
.vs/
[Bb]in/
[Oo]bj/
_UpgradeReport_Files/
[Pp]ackages/
Thumbs.db
Desktop.ini
.DS_Store
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ContentModelStore">
<e p="$PROJECT_DIR$" t="IncludeFlat">
<e p="ConsoleApp" t="IncludeRecursive">
<e p="app.db" t="Include" />
<e p="bin" t="ExcludeRecursive" />
<e p="ConsoleApp.csproj" t="IncludeRecursive" />
<e p="obj" t="ExcludeRecursive">
<e p="Debug" t="Include">
<e p="netcoreapp3.1" t="Include">
<e p="ConsoleApp.AssemblyInfo.cs" t="Include" />
</e>
</e>
</e>
<e p="Program.cs" t="Include" />
</e>
<e p="DAL" t="IncludeRecursive">
<e p="AppDbContext.cs" t="Include" />
<e p="bin" t="ExcludeRecursive" />
<e p="DAL.csproj" t="IncludeRecursive" />
<e p="Migrations" t="Include">
<e p="20201016102442_InitialCreate.cs" t="Include" />
<e p="20201016102442_InitialCreate.Designer.cs" t="Include" />
<e p="AppDbContextModelSnapshot.cs" t="Include" />
</e>
<e p="obj" t="ExcludeRecursive">
<e p="Debug" t="Include">
<e p="netstandard2.1" t="Include">
<e p="DAL.AssemblyInfo.cs" t="Include" />
</e>
</e>
</e>
</e>
<e p="DbDemo.sln" t="IncludeFlat" />
<e p="Domain" t="IncludeRecursive">
<e p="bin" t="ExcludeRecursive" />
<e p="Domain.csproj" t="IncludeRecursive" />
<e p="Grade.cs" t="Include" />
<e p="Homework.cs" t="Include" />
<e p="obj" t="ExcludeRecursive">
<e p="Debug" t="Include">
<e p="netstandard2.1" t="Include">
<e p="Domain.AssemblyInfo.cs" t="Include" />
</e>
</e>
</e>
<e p="Student.cs" t="Include" />
</e>
<e p="packages" t="ExcludeRecursive" />
</e>
<e p="$APPLICATION_CONFIG_DIR$/consoles/db" t="IncludeRecursive" />
<e p="$APPLICATION_CONFIG_DIR$/extensions" t="IncludeRecursive" />
<e p="$APPLICATION_CONFIG_DIR$/scratches" t="IncludeRecursive" />
<e p="$USER_HOME$/Library/Caches/JetBrains/Rider2020.2/extResources" t="IncludeRecursive" />
<e p="$USER_HOME$/Library/Caches/JetBrains/Rider2020.2/resharper-host/local/Transient/Rider/v202/SolutionCaches/_DbDemo.-734520131.00" t="ExcludeRecursive" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ContentModelUserStore">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.DbDemo/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.DbDemo/riderModule.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="vcsConfiguration" value="2" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="RIDER_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/../.." />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DAL\DAL.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
using System;
using DAL;
using Microsoft.EntityFrameworkCore;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
// dotnet tool update --global dotnet-ef
// dotnet tool install --global dotnet-ef
Console.WriteLine("Hello EF Core Demo!");
using var db = new AppDbContext();
foreach (var student in db.Students)
{
Console.WriteLine(student);
}
}
}
}
\ No newline at end of file
using System;
using Domain;
using Microsoft.EntityFrameworkCore;
namespace DAL
{
/*
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
*/
public class AppDbContext : DbContext
{
public DbSet<Student> Students { get; set; }
public DbSet<Homework> Homeworks { get; set; }
public DbSet<Grade> Grades { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseSqlite("Data Source=/Users/akaver/Development/!/app.db");
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>
</Project>
// <auto-generated />
using DAL;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace DAL.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20201016102442_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.9");
modelBuilder.Entity("Domain.Grade", b =>
{
b.Property<int>("GradeId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("GradeValue")
.HasColumnType("INTEGER");
b.Property<int>("HomeworkId")
.HasColumnType("INTEGER");
b.Property<int>("StudentId")
.HasColumnType("INTEGER");
b.HasKey("GradeId");
b.HasIndex("HomeworkId");
b.HasIndex("StudentId");
b.ToTable("Grades");
});
modelBuilder.Entity("Domain.Homework", b =>
{
b.Property<int>("HomeworkId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.HasKey("HomeworkId");
b.ToTable("Homeworks");
});
modelBuilder.Entity("Domain.Student", b =>
{
b.Property<int>("StudentId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.HasKey("StudentId");
b.ToTable("Students");
});
modelBuilder.Entity("Domain.Grade", b =>
{
b.HasOne("Domain.Homework", "Homework")
.WithMany("Grades")
.HasForeignKey("HomeworkId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Domain.Student", "Student")
.WithMany("Grades")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace DAL.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Homeworks",
columns: table => new
{
HomeworkId = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Description = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Homeworks", x => x.HomeworkId);
});
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
StudentId = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
FirstName = table.Column<string>(nullable: true),
LastName = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Students", x => x.StudentId);
});
migrationBuilder.CreateTable(
name: "Grades",
columns: table => new
{
GradeId = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
GradeValue = table.Column<int>(nullable: false),
StudentId = table.Column<int>(nullable: false),
HomeworkId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Grades", x => x.GradeId);
table.ForeignKey(
name: "FK_Grades_Homeworks_HomeworkId",
column: x => x.HomeworkId,
principalTable: "Homeworks",
principalColumn: "HomeworkId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Grades_Students_StudentId",
column: x => x.StudentId,
principalTable: "Students",
principalColumn: "StudentId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Grades_HomeworkId",
table: "Grades",
column: "HomeworkId");
migrationBuilder.CreateIndex(
name: "IX_Grades_StudentId",
table: "Grades",
column: "StudentId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Grades");
migrationBuilder.DropTable(
name: "Homeworks");
migrationBuilder.DropTable(
name: "Students");
}
}
}
// <auto-generated />
using DAL;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace DAL.Migrations
{
[DbContext(typeof(AppDbContext))]
partial class AppDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.9");
modelBuilder.Entity("Domain.Grade", b =>
{
b.Property<int>("GradeId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("GradeValue")
.HasColumnType("INTEGER");
b.Property<int>("HomeworkId")
.HasColumnType("INTEGER");
b.Property<int>("StudentId")
.HasColumnType("INTEGER");
b.HasKey("GradeId");
b.HasIndex("HomeworkId");
b.HasIndex("StudentId");
b.ToTable("Grades");
});
modelBuilder.Entity("Domain.Homework", b =>
{
b.Property<int>("HomeworkId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.HasKey("HomeworkId");
b.ToTable("Homeworks");
});
modelBuilder.Entity("Domain.Student", b =>
{
b.Property<int>("StudentId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.HasKey("StudentId");
b.ToTable("Students");
});
modelBuilder.Entity("Domain.Grade", b =>
{
b.HasOne("Domain.Homework", "Homework")
.WithMany("Grades")
.HasForeignKey("HomeworkId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Domain.Student", "Student")
.WithMany("Grades")
.HasForeignKey("StudentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{4668C514-C666-474D-9EB0-F9495E6CF589}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "Domain\Domain.csproj", "{CEF01487-DCF3-4D42-B493-D9260D5E3790}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL", "DAL\DAL.csproj", "{8DA98771-7D90-44AD-BB99-E25D8F829F7F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4668C514-C666-474D-9EB0-F9495E6CF589}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4668C514-C666-474D-9EB0-F9495E6CF589}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4668C514-C666-474D-9EB0-F9495E6CF589}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4668C514-C666-474D-9EB0-F9495E6CF589}.Release|Any CPU.Build.0 = Release|Any CPU
{CEF01487-DCF3-4D42-B493-D9260D5E3790}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CEF01487-DCF3-4D42-B493-D9260D5E3790}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEF01487-DCF3-4D42-B493-D9260D5E3790}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEF01487-DCF3-4D42-B493-D9260D5E3790}.Release|Any CPU.Build.0 = Release|Any CPU
{8DA98771-7D90-44AD-BB99-E25D8F829F7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8DA98771-7D90-44AD-BB99-E25D8F829F7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DA98771-7D90-44AD-BB99-E25D8F829F7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DA98771-7D90-44AD-BB99-E25D8F829F7F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
</Project>
namespace Domain
{
public class Grade
{
public int GradeId { get; set; }
public int GradeValue { get; set; }
// FK - Foreign Key (type has to match with PK in another entity)
public int StudentId { get; set; }
public Student Student { get; set; }
public int HomeworkId { get; set; }
public Homework Homework { get; set; }
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment