Skip to content

Commit f8eddd6

Browse files
authored
Add CodeFirst examples for .NET 6 and 8 (#785)
1 parent 1a345d8 commit f8eddd6

39 files changed

+5872
-0
lines changed

System.Linq.Dynamic.Core.sln

+62
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RadzenDataGrid.BlazorApp",
140140
EndProject
141141
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp_net6.0_EF6_Sqlite", "src-console\ConsoleAppEF6_Sqlite\ConsoleApp_net6.0_EF6_Sqlite.csproj", "{CA03FD55-9DAB-4827-9A35-A96D3804B311}"
142142
EndProject
143+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src-examples", "src-examples", "{BCA2A024-9032-4E56-A6C4-17A15D921728}"
144+
ProjectSection(SolutionItems) = preProject
145+
src-examples\README.md = src-examples\README.md
146+
EndProjectSection
147+
EndProject
148+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeFirst.DataAccess", "src-examples\CodeFirst.DataAccess\CodeFirst.DataAccess.csproj", "{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}"
149+
EndProject
150+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeFirst.ConsoleApp", "src-examples\CodeFirst.ConsoleApp\CodeFirst.ConsoleApp.csproj", "{9E0D0994-7D84-40FF-8383-189F142FEF11}"
151+
EndProject
152+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeFirst.ConsoleApp8", "src-examples\CodeFirst.ConsoleApp8\CodeFirst.ConsoleApp8.csproj", "{68C7FF71-54F6-4D68-B419-65D1B10206D4}"
153+
EndProject
143154
Global
144155
GlobalSection(SolutionConfigurationPlatforms) = preSolution
145156
Debug|Any CPU = Debug|Any CPU
@@ -858,6 +869,54 @@ Global
858869
{51074A4C-15C2-4E72-81F2-2FC53903553B}.Release|x64.Build.0 = Release|Any CPU
859870
{51074A4C-15C2-4E72-81F2-2FC53903553B}.Release|x86.ActiveCfg = Release|Any CPU
860871
{51074A4C-15C2-4E72-81F2-2FC53903553B}.Release|x86.Build.0 = Release|Any CPU
872+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
873+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
874+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Debug|ARM.ActiveCfg = Debug|Any CPU
875+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Debug|ARM.Build.0 = Debug|Any CPU
876+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Debug|x64.ActiveCfg = Debug|Any CPU
877+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Debug|x64.Build.0 = Debug|Any CPU
878+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Debug|x86.ActiveCfg = Debug|Any CPU
879+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Debug|x86.Build.0 = Debug|Any CPU
880+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
881+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Release|Any CPU.Build.0 = Release|Any CPU
882+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Release|ARM.ActiveCfg = Release|Any CPU
883+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Release|ARM.Build.0 = Release|Any CPU
884+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Release|x64.ActiveCfg = Release|Any CPU
885+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Release|x64.Build.0 = Release|Any CPU
886+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Release|x86.ActiveCfg = Release|Any CPU
887+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Release|x86.Build.0 = Release|Any CPU
888+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
889+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Debug|Any CPU.Build.0 = Debug|Any CPU
890+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Debug|ARM.ActiveCfg = Debug|Any CPU
891+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Debug|ARM.Build.0 = Debug|Any CPU
892+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Debug|x64.ActiveCfg = Debug|Any CPU
893+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Debug|x64.Build.0 = Debug|Any CPU
894+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Debug|x86.ActiveCfg = Debug|Any CPU
895+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Debug|x86.Build.0 = Debug|Any CPU
896+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Release|Any CPU.ActiveCfg = Release|Any CPU
897+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Release|Any CPU.Build.0 = Release|Any CPU
898+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Release|ARM.ActiveCfg = Release|Any CPU
899+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Release|ARM.Build.0 = Release|Any CPU
900+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Release|x64.ActiveCfg = Release|Any CPU
901+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Release|x64.Build.0 = Release|Any CPU
902+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Release|x86.ActiveCfg = Release|Any CPU
903+
{9E0D0994-7D84-40FF-8383-189F142FEF11}.Release|x86.Build.0 = Release|Any CPU
904+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
905+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
906+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Debug|ARM.ActiveCfg = Debug|Any CPU
907+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Debug|ARM.Build.0 = Debug|Any CPU
908+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Debug|x64.ActiveCfg = Debug|Any CPU
909+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Debug|x64.Build.0 = Debug|Any CPU
910+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Debug|x86.ActiveCfg = Debug|Any CPU
911+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Debug|x86.Build.0 = Debug|Any CPU
912+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
913+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Release|Any CPU.Build.0 = Release|Any CPU
914+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Release|ARM.ActiveCfg = Release|Any CPU
915+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Release|ARM.Build.0 = Release|Any CPU
916+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Release|x64.ActiveCfg = Release|Any CPU
917+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Release|x64.Build.0 = Release|Any CPU
918+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Release|x86.ActiveCfg = Release|Any CPU
919+
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Release|x86.Build.0 = Release|Any CPU
861920
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
862921
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|Any CPU.Build.0 = Debug|Any CPU
863922
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|ARM.ActiveCfg = Debug|Any CPU
@@ -923,6 +982,9 @@ Global
923982
{9000129D-322D-4FE6-9C47-75464577C374} = {DBD7D9B6-FCC7-4650-91AF-E6457573A68F}
924983
{ABB1BF71-8927-49BB-99F3-70BCB2CD161E} = {8463ED7E-69FB-49AE-85CF-0791AFD98E38}
925984
{51074A4C-15C2-4E72-81F2-2FC53903553B} = {122BC4FA-7563-4E35-9D17-077F16F1629F}
985+
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4} = {BCA2A024-9032-4E56-A6C4-17A15D921728}
986+
{9E0D0994-7D84-40FF-8383-189F142FEF11} = {BCA2A024-9032-4E56-A6C4-17A15D921728}
987+
{68C7FF71-54F6-4D68-B419-65D1B10206D4} = {BCA2A024-9032-4E56-A6C4-17A15D921728}
926988
{CA03FD55-9DAB-4827-9A35-A96D3804B311} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
927989
EndGlobalSection
928990
GlobalSection(ExtensibilityGlobals) = postSolution
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore6\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore6.csproj" />
10+
<ProjectReference Include="..\CodeFirst.DataAccess\CodeFirst.DataAccess.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Linq;
4+
using System.Linq.Dynamic.Core;
5+
using System.Threading.Tasks;
6+
using CodeFirst.DataAccess.Factories;
7+
using CodeFirst.DataAccess.Repositories;
8+
using Microsoft.EntityFrameworkCore;
9+
10+
namespace CodeFirst.ConsoleApp;
11+
12+
public static class Program
13+
{
14+
private static async Task Main()
15+
{
16+
var sqlFactory = new SqlServerDbContextFactory();
17+
18+
await using var context = sqlFactory.CreateDbContext(Array.Empty<string>());
19+
20+
var stopwatch = ValueStopwatch.StartNew();
21+
var query1 = context.Movies.Include(x => x.Copies).Where("Title.Contains(\"e\")").ToDynamicList();
22+
Console.WriteLine($"Elapsed time: {stopwatch.GetElapsedTime().TotalMilliseconds}ms");
23+
query1.ToList().ToList().ForEach(Console.WriteLine);
24+
25+
Console.WriteLine(new string('-', 80));
26+
27+
stopwatch = ValueStopwatch.StartNew();
28+
var query2 = context.Movies.Include(x => x.Copies).Where("Title.Contains(\"e\")").ToDynamicList();
29+
Console.WriteLine($"Elapsed time: {stopwatch.GetElapsedTime().TotalMilliseconds}ms");
30+
query2.ToList().ToList().ForEach(Console.WriteLine);
31+
32+
//var sqlServerRepo = new MoviesRepository(sqlFactory.CreateDbContext(Array.Empty<string>()));
33+
//var movies = await sqlServerRepo.GetAllAsync();
34+
//movies.ToList().ForEach(Console.WriteLine);
35+
//var getById = await sqlServerRepo.GetByIdAsync(3);
36+
//Console.WriteLine(getById.Title);
37+
38+
//var postFactory = new PostgresDbContextFactory();
39+
//var postgresRepo = new MoviesRepository(postFactory.CreateDbContext(Array.Empty<string>()));
40+
//movies = await postgresRepo.GetAllAsync();
41+
//movies.ToList().ForEach(Console.WriteLine);
42+
//getById = await postgresRepo.GetByIdAsync(3);
43+
//Console.WriteLine(getById.Title);
44+
}
45+
46+
/// <summary>
47+
/// Copied from https://github.com/dotnet/aspnetcore/blob/main/src/Shared/ValueStopwatch/ValueStopwatch.cs
48+
/// </summary>
49+
internal readonly struct ValueStopwatch
50+
{
51+
#if !NET7_0_OR_GREATER
52+
private static readonly double TimestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;
53+
#endif
54+
55+
private readonly long _startTimestamp;
56+
57+
public bool IsActive => _startTimestamp != 0;
58+
59+
private ValueStopwatch(long startTimestamp)
60+
{
61+
_startTimestamp = startTimestamp;
62+
}
63+
64+
public static ValueStopwatch StartNew() => new(Stopwatch.GetTimestamp());
65+
66+
public TimeSpan GetElapsedTime()
67+
{
68+
// Start timestamp can't be zero in an initialized ValueStopwatch. It would have to be literally the first thing executed when the machine boots to be 0.
69+
// So it being 0 is a clear indication of default(ValueStopwatch)
70+
if (!IsActive)
71+
{
72+
throw new InvalidOperationException("An uninitialized, or 'default', ValueStopwatch cannot be used to get elapsed time.");
73+
}
74+
75+
var end = Stopwatch.GetTimestamp();
76+
77+
#if !NET7_0_OR_GREATER
78+
var timestampDelta = end - _startTimestamp;
79+
var ticks = (long)(TimestampToTicks * timestampDelta);
80+
return new TimeSpan(ticks);
81+
#else
82+
return Stopwatch.GetElapsedTime(_startTimestamp, end);
83+
#endif
84+
}
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="..\CodeFirst.ConsoleApp\Program.cs" Link="Program.cs" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore8\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore8.csproj" />
14+
<ProjectReference Include="..\CodeFirst.DataAccess\CodeFirst.DataAccess.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
8+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.28" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.28" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.28">
11+
<PrivateAssets>all</PrivateAssets>
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
</PackageReference>
14+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.22" />
15+
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.28">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
22+
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
23+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
24+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
25+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
26+
<PrivateAssets>all</PrivateAssets>
27+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
28+
</PackageReference>
29+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
30+
31+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
32+
<PrivateAssets>all</PrivateAssets>
33+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
34+
</PackageReference>
35+
</ItemGroup>
36+
37+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using CodeFirst.DataAccess.Models;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
5+
6+
namespace CodeFirst.DataAccess.Configurations;
7+
8+
public class ActorsConfiguration : IEntityTypeConfiguration<Actors>
9+
{
10+
public void Configure(EntityTypeBuilder<Actors> builder)
11+
{
12+
builder.HasKey(e => e.ActorId)
13+
.HasName("actor_pkey");
14+
builder.Property(e => e.ActorId)
15+
.HasColumnName("actor_id");
16+
builder.Property(e => e.Firstname)
17+
.HasColumnName("first_name");
18+
builder.Property(e => e.Lastname)
19+
.HasColumnName("last_name");
20+
builder.Property(e => e.Birthday)
21+
.HasColumnName("birthday");
22+
builder.ToTable("actors");
23+
24+
builder.HasData(
25+
new Actors(1, "Arnold", "Schwarzenegger", Convert.ToDateTime("1947-07-30")),
26+
new Actors(2, "Anthony", "Daniels", Convert.ToDateTime("1946-02-21")),
27+
new Actors(3, "Harrison", "Ford", Convert.ToDateTime("1942-07-13")),
28+
new Actors(4, "Carrie", "Fisher", Convert.ToDateTime("1956-10-21")),
29+
new Actors(5, "Alec", "Guiness", Convert.ToDateTime("1914-04-02")),
30+
new Actors(6, "Peter", "Cushing", Convert.ToDateTime("1913-05-26")),
31+
new Actors(7, "David", "Prowse", Convert.ToDateTime("1944-05-19")),
32+
new Actors(8, "Peter", "Mayhew", Convert.ToDateTime("1935-07-01")),
33+
new Actors(9, "Michael", "Biehn", Convert.ToDateTime("1956-07-31")),
34+
new Actors(10, "Linda", "Hamilton", Convert.ToDateTime("1956-09-26")),
35+
new Actors(11, "Bill", "Murray", Convert.ToDateTime("1950-09-21")),
36+
new Actors(12, "Dan", "Aykroyd", Convert.ToDateTime("1952-07-01")),
37+
new Actors(13, "Sigourney", "Weaver", Convert.ToDateTime("1949-10-08")),
38+
new Actors(14, "Robert", "De Niro", Convert.ToDateTime("1943-08-17")),
39+
new Actors(15, "Jodie", "Foster", Convert.ToDateTime("1962-11-19")),
40+
new Actors(16, "Harvey", "Keitel", Convert.ToDateTime("1939-05-13")),
41+
new Actors(17, "Cybill", "Shepherd", Convert.ToDateTime("1950-02-18")),
42+
new Actors(18, "Tom", "Berenger", Convert.ToDateTime("1949-05-31")),
43+
new Actors(19, "Willem", "Dafoe", Convert.ToDateTime("1955-07-22")),
44+
new Actors(20, "Charlie", "Sheen", Convert.ToDateTime("1965-09-03")),
45+
new Actors(21, "Harrison", "Ford", Convert.ToDateTime("1942-07-13")),
46+
new Actors(22, "Emmanuelle", "Seigner", Convert.ToDateTime("1966-06-22")),
47+
new Actors(23, "Jean", "Reno", Convert.ToDateTime("1948-07-30")),
48+
new Actors(24, "Billy", "Crystal", Convert.ToDateTime("1948-03-14")),
49+
new Actors(25, "Lisa", "Kudrow", Convert.ToDateTime("1963-07-30")),
50+
new Actors(26, "Gary", "Oldman", Convert.ToDateTime("1958-03-21")),
51+
new Actors(27, "Natalie", "Portman", Convert.ToDateTime("1981-06-09")),
52+
new Actors(28, "Tom", "Cruise", Convert.ToDateTime("1962-07-03")));
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using CodeFirst.DataAccess.Models;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
5+
6+
namespace CodeFirst.DataAccess.Configurations;
7+
8+
public class ClientsConfiguration : IEntityTypeConfiguration<Clients>
9+
{
10+
public void Configure(EntityTypeBuilder<Clients> builder)
11+
{
12+
builder.HasKey(e => e.ClientId)
13+
.HasName("client_pkey");
14+
builder.Property(e => e.ClientId)
15+
.HasColumnName("client_id");
16+
builder.Property(e => e.Firstname)
17+
.HasColumnName("first_name");
18+
builder.Property(e => e.Lastname)
19+
.HasColumnName("last_name");
20+
builder.Property(e => e.Birthday)
21+
.HasColumnName("birthday");
22+
23+
builder.ToTable("clients");
24+
25+
builder.HasData(
26+
new Clients(1, "Hank", "Hill", Convert.ToDateTime("1954-04-19")),
27+
new Clients(2, "Brian", "Griffin", Convert.ToDateTime("2011-09-11")),
28+
new Clients(3, "Gary", "Goodspeed", Convert.ToDateTime("1989-03-12")),
29+
new Clients(4, "Bob", "Belcher", Convert.ToDateTime("1977-01-23")),
30+
new Clients(5, "Lisa", "Simpson", Convert.ToDateTime("2012-05-09")),
31+
new Clients(6, "Rick", "Sanchez", Convert.ToDateTime("1965-03-17")));
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using CodeFirst.DataAccess.Models;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
4+
5+
namespace CodeFirst.DataAccess.Configurations;
6+
7+
public class CopiesConfiguration : IEntityTypeConfiguration<Copies>
8+
{
9+
public void Configure(EntityTypeBuilder<Copies> builder)
10+
{
11+
builder.HasKey(e => e.CopyId)
12+
.HasName("copies_pkey");
13+
14+
builder.Property(e => e.MovieId)
15+
.IsRequired()
16+
.HasColumnName("movie_id");
17+
18+
builder.Property(e => e.CopyId)
19+
.HasColumnName("copy_id");
20+
21+
builder.Property(e => e.Available)
22+
.HasColumnName("available");
23+
24+
builder.ToTable("copies");
25+
builder.HasData(new Copies(1, 1, true),
26+
new Copies(2, 1, false),
27+
new Copies(3, 2, true),
28+
new Copies(4, 3, true),
29+
new Copies(5, 3, false),
30+
new Copies(6, 3, true),
31+
new Copies(7, 4, true),
32+
new Copies(8, 5, false),
33+
new Copies(9, 6, true),
34+
new Copies(10, 6, false),
35+
new Copies(11, 6, true),
36+
new Copies(12, 7, true),
37+
new Copies(13, 7, true),
38+
new Copies(14, 8, false),
39+
new Copies(15, 9, true),
40+
new Copies(16, 10, true),
41+
new Copies(17, 10, false),
42+
new Copies(18, 10, true),
43+
new Copies(19, 10, true),
44+
new Copies(20, 10, true));
45+
}
46+
}

0 commit comments

Comments
 (0)