modification mais problème installation ef

part1
Tom RAMBEAU 1 year ago
parent 3b773dea43
commit 5ba4977cae

@ -0,0 +1,22 @@
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=tp1.Books.db");
}
}
}

@ -0,0 +1,22 @@
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;
}
}
}

@ -0,0 +1,22 @@
<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>

@ -0,0 +1,22 @@
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"));
}
}
}

@ -0,0 +1,40 @@
using Library;
using Library.DbContextLib;
using Library.Entities;
using Microsoft.Extensions.Options;
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using (var context = new LibraryContext())
{
BookEntity chewie = new BookEntity("B3", "test", "test2");
BookEntity yoda = new BookEntity ("B4", "test", "test2");
BookEntity ewok = new BookEntity ("C5", "test", "test3");
context.BooksSet.Add(chewie);
context.BooksSet.Add(yoda);
context.BooksSet.Add(ewok);
context.SaveChanges();
}
using (var context = new LibraryContext())
{
foreach (var n in context.BooksSet)
{
Console.WriteLine($"{n.ID} - {n.Title}");
}
context.SaveChanges();
}
using (var context = new LibraryContext())
{
var eBooks = context.BooksSet.Where(b => b.Title.StartsWith("B")).First();
Console.WriteLine($"{eBooks.Title} (born in {eBooks.Author})");
eBooks.Title = "Wicket";
context.SaveChanges();
}

@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</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>
<ItemGroup>
<ProjectReference Include="..\Library\Library.csproj" />
</ItemGroup>
</Project>

@ -3,13 +3,9 @@ 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}") = "TestStubEF", "tp1\TestStubEF.csproj", "{2097BC86-5063-42A3-83E2-1004732AC629}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestStub", "TestStub\TestStub.csproj", "{8960D74C-259D-4779-80B6-789BA257D2B2}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{19774C29-80C4-4B8C-A7D9-8F42576C4D1C}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library", "Library\Library.csproj", "{CDD5A87A-187A-4BC1-9E23-5559A2211B55}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{785FFEAF-A688-470C-AB63-5F83219177BC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{56AB577F-DC4D-4DDE-81ED-6376FB52D5EA}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -17,22 +13,14 @@ Global
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2097BC86-5063-42A3-83E2-1004732AC629}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8960D74C-259D-4779-80B6-789BA257D2B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2097BC86-5063-42A3-83E2-1004732AC629}.Debug|Any CPU.Build.0 = Debug|Any CPU {8960D74C-259D-4779-80B6-789BA257D2B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2097BC86-5063-42A3-83E2-1004732AC629}.Release|Any CPU.ActiveCfg = Release|Any CPU {8960D74C-259D-4779-80B6-789BA257D2B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2097BC86-5063-42A3-83E2-1004732AC629}.Release|Any CPU.Build.0 = Release|Any CPU {8960D74C-259D-4779-80B6-789BA257D2B2}.Release|Any CPU.Build.0 = Release|Any CPU
{19774C29-80C4-4B8C-A7D9-8F42576C4D1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CDD5A87A-187A-4BC1-9E23-5559A2211B55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19774C29-80C4-4B8C-A7D9-8F42576C4D1C}.Debug|Any CPU.Build.0 = Debug|Any CPU {CDD5A87A-187A-4BC1-9E23-5559A2211B55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19774C29-80C4-4B8C-A7D9-8F42576C4D1C}.Release|Any CPU.ActiveCfg = Release|Any CPU {CDD5A87A-187A-4BC1-9E23-5559A2211B55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19774C29-80C4-4B8C-A7D9-8F42576C4D1C}.Release|Any CPU.Build.0 = Release|Any CPU {CDD5A87A-187A-4BC1-9E23-5559A2211B55}.Release|Any CPU.Build.0 = Release|Any CPU
{785FFEAF-A688-470C-AB63-5F83219177BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{785FFEAF-A688-470C-AB63-5F83219177BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{785FFEAF-A688-470C-AB63-5F83219177BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{785FFEAF-A688-470C-AB63-5F83219177BC}.Release|Any CPU.Build.0 = Release|Any CPU
{56AB577F-DC4D-4DDE-81ED-6376FB52D5EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56AB577F-DC4D-4DDE-81ED-6376FB52D5EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56AB577F-DC4D-4DDE-81ED-6376FB52D5EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56AB577F-DC4D-4DDE-81ED-6376FB52D5EA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -1,2 +1,4 @@
// See https://aka.ms/new-console-template for more information using Microsoft.EntityFrameworkCore.Design;
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!"); Console.WriteLine("Hello, World!");

@ -19,6 +19,7 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save