changement conception pour migrations et moitié part2

part2
Tom RAMBEAU 1 year ago
parent e1fcd7d1f9
commit 589a4bd413

@ -1,21 +1,23 @@
using Microsoft.EntityFrameworkCore; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Entities; using Entities;
namespace DbContextLib namespace DbContextLib
{ {
public class LibraryContext : DbContext public class LibraryContext : DbContext
{ {
public DbSet<PersonEntity> PersonSet { get; set; }
public DbSet<BookEntity> BooksSet { get; set; } public DbSet<BookEntity> BooksSet { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
optionsBuilder.UseSqlite($"Data Source=tp1.Books.db"); optionsBuilder.UseSqlite("Data Source=tp.Books.db");
} }
} }
} }

@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace DbContextLib.Migrations namespace DbContextLib.Migrations
{ {
[DbContext(typeof(LibraryContext))] [DbContext(typeof(LibraryContext))]
[Migration("20240201082456_BooksMigration")] [Migration("20240209010818_Mg")]
partial class BooksMigration partial class Mg
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)

@ -5,7 +5,7 @@
namespace DbContextLib.Migrations namespace DbContextLib.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class BooksMigration : Migration public partial class Mg : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)

Binary file not shown.

@ -1,13 +1,25 @@
using System.Reflection; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities namespace Entities
{ {
public class BookEntity public class BookEntity
{ {
public int ID { get; set; } public int ID { get; set; }
public string Title { get; set; } public string Title { get; set; }
public string Author { get; set; } public string Author { get; set; }
public string Isbn { get; set; } public string Isbn { get; set; }
public PersonEntity? Person { get; set; }
public BookEntity(string title, string author, string isbn) {
Title = title;
Author = author;
Isbn = isbn;
}
} }
} }

@ -6,17 +6,4 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project> </Project>

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities
{
public class PersonEntity
{
public long Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public ICollection<BookEntity> Books { get; set; }
}
}

@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Library.Entities;
namespace Library.DbContextLib
{
public class LibraryContext : DbContext
{
public DbSet<BookEntity> BooksSet { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=tp.Books.db");
}
}
}

@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Library.Entities
{
public class BookEntity
{
public int ID { get; set; }
public string Title { get; set; }
public string Author { get; set; }
public string Isbn { get; set; }
public BookEntity(string title, string author, string isbn) {
Title = title;
Author = author;
Isbn = isbn;
}
}
}

@ -1,22 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Library.DbContextLib;
using Library.Entities;
using Microsoft.EntityFrameworkCore;
namespace Library.StubbedContextLib
{
public class StubbedContext : DbContext
{
public List<BookEntity> Books { get; set; }
public StubbedContext() {
Books.Add(new BookEntity("test", "test", "test"));
Books.Add(new BookEntity("test2", "test2", "test2"));
}
}
}

Binary file not shown.

@ -3,15 +3,15 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using TestStub; using StubbedContextLib;
#nullable disable #nullable disable
namespace TestStub.Migrations namespace StubbedContextLib.Migrations
{ {
[DbContext(typeof(LibraryContext))] [DbContext(typeof(StubbedContext))]
[Migration("20240201143359_BooksMigrations")] [Migration("20240209013745_Mg")]
partial class BooksMigrations partial class Mg
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -19,7 +19,7 @@ namespace TestStub.Migrations
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.1"); modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
modelBuilder.Entity("TestStub.BookEntity", b => modelBuilder.Entity("Entities.BookEntity", b =>
{ {
b.Property<int>("ID") b.Property<int>("ID")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()

@ -2,10 +2,10 @@
#nullable disable #nullable disable
namespace TestStub.Migrations namespace StubbedContextLib.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class BooksMigrations : Migration public partial class Mg : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)

@ -2,21 +2,21 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using TestStub; using StubbedContextLib;
#nullable disable #nullable disable
namespace TestStub.Migrations namespace StubbedContextLib.Migrations
{ {
[DbContext(typeof(LibraryContext))] [DbContext(typeof(StubbedContext))]
partial class LibraryContextModelSnapshot : ModelSnapshot partial class StubbedContextModelSnapshot : ModelSnapshot
{ {
protected override void BuildModel(ModelBuilder modelBuilder) protected override void BuildModel(ModelBuilder modelBuilder)
{ {
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.1"); modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
modelBuilder.Entity("TestStub.BookEntity", b => modelBuilder.Entity("Entities.BookEntity", b =>
{ {
b.Property<int>("ID") b.Property<int>("ID")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()

@ -1,11 +1,23 @@
using Entities; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DbContextLib;
using Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace StubbedContextLib namespace StubbedContextLib
{ {
public class StubbedContext : DbContext public class StubbedContext : LibraryContext
{ {
public List<PersonEntity> Persons { get; set; } = new List<PersonEntity>();
public List<BookEntity> Books { get; set; } = new List<BookEntity>();
public StubbedContext() {
Books.Add(new BookEntity("test", "test", "test"));
Books.Add(new BookEntity("test2", "test2", "test2"));
}
} }
} }

@ -19,9 +19,9 @@
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" /> <ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\Entities\Entities.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestStub
{
public class BookEntity
{
public int ID { get; set; }
public string Title { get; set; }
public string Author { get; set; }
public string Isbn { get; set; }
public BookEntity(string title, string author, string isbn) {
Title = title;
Author = author;
Isbn = isbn;
}
}
}

@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Library.Entities;
namespace TestStub
{
public class LibraryContext : DbContext
{
public DbSet<BookEntity> BooksSet { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=tp.Books.db");
}
}
}

@ -1,4 +1,6 @@
using TestStub; using StubbedContextLib;
using Entities;
using DbContextLib;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
// See https://aka.ms/new-console-template for more information // See https://aka.ms/new-console-template for more information

@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Library.DbContextLib;
using Library.Entities;
using Microsoft.EntityFrameworkCore;
namespace TestStub
{
public class StubbedContext : DbContext
{
public List<BookEntity> Books { get; set; }
public StubbedContext() {
Books.Add(new BookEntity("test", "test", "test"));
Books.Add(new BookEntity("test2", "test2", "test2"));
}
}
}

@ -22,7 +22,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Library\Library.csproj" /> <ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\Entities\Entities.csproj" />
<ProjectReference Include="..\StubbedContextLib\StubbedContextLib.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

Binary file not shown.

@ -3,9 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.8.34330.188 VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestStub", "TestStub\TestStub.csproj", "{8960D74C-259D-4779-80B6-789BA257D2B2}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestStub", "TestStub\TestStub.csproj", "{8960D74C-259D-4779-80B6-789BA257D2B2}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library", "Library\Library.csproj", "{CDD5A87A-187A-4BC1-9E23-5559A2211B55}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{A4130190-8883-42DE-89CA-3DF205DE710A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{F793C071-E178-48D3-BBE6-22F99D102C2B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{5C673F26-2E43-4AA8-944E-1A3B309927CF}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -17,10 +21,18 @@ Global
{8960D74C-259D-4779-80B6-789BA257D2B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {8960D74C-259D-4779-80B6-789BA257D2B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8960D74C-259D-4779-80B6-789BA257D2B2}.Release|Any CPU.ActiveCfg = Release|Any CPU {8960D74C-259D-4779-80B6-789BA257D2B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8960D74C-259D-4779-80B6-789BA257D2B2}.Release|Any CPU.Build.0 = Release|Any CPU {8960D74C-259D-4779-80B6-789BA257D2B2}.Release|Any CPU.Build.0 = Release|Any CPU
{CDD5A87A-187A-4BC1-9E23-5559A2211B55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A4130190-8883-42DE-89CA-3DF205DE710A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CDD5A87A-187A-4BC1-9E23-5559A2211B55}.Debug|Any CPU.Build.0 = Debug|Any CPU {A4130190-8883-42DE-89CA-3DF205DE710A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CDD5A87A-187A-4BC1-9E23-5559A2211B55}.Release|Any CPU.ActiveCfg = Release|Any CPU {A4130190-8883-42DE-89CA-3DF205DE710A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CDD5A87A-187A-4BC1-9E23-5559A2211B55}.Release|Any CPU.Build.0 = Release|Any CPU {A4130190-8883-42DE-89CA-3DF205DE710A}.Release|Any CPU.Build.0 = Release|Any CPU
{F793C071-E178-48D3-BBE6-22F99D102C2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F793C071-E178-48D3-BBE6-22F99D102C2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F793C071-E178-48D3-BBE6-22F99D102C2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F793C071-E178-48D3-BBE6-22F99D102C2B}.Release|Any CPU.Build.0 = Release|Any CPU
{5C673F26-2E43-4AA8-944E-1A3B309927CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C673F26-2E43-4AA8-944E-1A3B309927CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5C673F26-2E43-4AA8-944E-1A3B309927CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C673F26-2E43-4AA8-944E-1A3B309927CF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save