changed samples ex_042_010, 11, 12 about many to many: added Include and ThenInclude

updatesEFSamplesToNetCore3
Marc CHEVALDONNE 6 years ago
parent 868772cc1f
commit 93d98a330d

@ -529,7 +529,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ex_050_010_Threading_en_UWP
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ex_052_006_problématique_6_UWP", "ex_052_006_problématique_6_UWP\ex_052_006_problématique_6_UWP.csproj", "{BCE167F6-6323-46FC-A112-D9941A75815A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ex_042_011_EF_CF_Many_to_Many_FluentAPI", "ex_042_011_EF_CF_Many_to_Many_FluentAPI\ex_042_011_EF_CF_Many_to_Many_FluentAPI.csproj", "{4F8FDCA9-D98C-4137-BD14-C255506209B0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ex_042_011_EF_CF_Many_to_Many_FluentAPI", "ex_042_011_EF_CF_Many_to_Many_FluentAPI\ex_042_011_EF_CF_Many_to_Many_FluentAPI.csproj", "{4F8FDCA9-D98C-4137-BD14-C255506209B0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ex_042_012_EF_CF_Many_to_Many_procurators", "ex_042_012_EF_CF_Many_to_Many_procurators\ex_042_012_EF_CF_Many_to_Many_procurators.csproj", "{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -4467,6 +4469,26 @@ Global
{4F8FDCA9-D98C-4137-BD14-C255506209B0}.Release|x64.Build.0 = Release|Any CPU
{4F8FDCA9-D98C-4137-BD14-C255506209B0}.Release|x86.ActiveCfg = Release|Any CPU
{4F8FDCA9-D98C-4137-BD14-C255506209B0}.Release|x86.Build.0 = Release|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Debug|ARM.ActiveCfg = Debug|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Debug|ARM.Build.0 = Debug|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Debug|ARM64.Build.0 = Debug|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Debug|x64.ActiveCfg = Debug|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Debug|x64.Build.0 = Debug|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Debug|x86.ActiveCfg = Debug|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Debug|x86.Build.0 = Debug|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Release|Any CPU.Build.0 = Release|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Release|ARM.ActiveCfg = Release|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Release|ARM.Build.0 = Release|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Release|ARM64.ActiveCfg = Release|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Release|ARM64.Build.0 = Release|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Release|x64.ActiveCfg = Release|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Release|x64.Build.0 = Release|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Release|x86.ActiveCfg = Release|Any CPU
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -4721,6 +4743,7 @@ Global
{0D922BCD-7C0F-43FF-A015-F547716B8284} = {BF2B43D0-95C2-402B-92C3-D2464C117A6E}
{BCE167F6-6323-46FC-A112-D9941A75815A} = {7FDA2D7D-5385-485D-B8B5-60727583D6ED}
{4F8FDCA9-D98C-4137-BD14-C255506209B0} = {593200F9-6D14-43BC-9289-8BB75FAC6552}
{A14CDD6E-3E6E-4E7A-9277-3F00C0F658FD} = {593200F9-6D14-43BC-9289-8BB75FAC6552}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8D31C3AE-36FF-4667-A2A7-0E670245A59E}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
using Microsoft.EntityFrameworkCore;
namespace ex_042_010_EF_CF_Many_to_Many
{
@ -33,9 +34,11 @@ namespace ex_042_010_EF_CF_Many_to_Many
{
//choix de la stratégie et remplissage avec des données stubbées
DbContextInitializer.Seed(db);
}
using (AlbumArtisteDBEntities db = new AlbumArtisteDBEntities())
{
WriteLine("Albums : ");
foreach (var album in db.Albums)
foreach (var album in db.Albums.Include(a => a.AlbumsArtistes).ThenInclude(aa => aa.Artiste))
{
WriteLine($"\t{album.UniqueId}: {album.Titre} (sorti le : {album.DateDeSortie.ToString("d")})");
foreach (var artiste in album.Artistes)
@ -47,7 +50,7 @@ namespace ex_042_010_EF_CF_Many_to_Many
WriteLine();
WriteLine("Artistes :");
foreach (var artiste in db.Artistes)
foreach (var artiste in db.Artistes.Include(a => a.AlbumsArtistes).ThenInclude(aa => aa.Album))
{
var annéeDeMort = artiste.DateDeMort.HasValue ? $" - {artiste.DateDeMort.Value.Year}" : "";
var titresAlbums = artiste.Albums.Aggregate(String.Empty, (albums, album) => albums + $"\"{album.Titre}\" ");

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
using Microsoft.EntityFrameworkCore;
namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
{
@ -33,9 +34,12 @@ namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
{
//choix de la stratégie et remplissage avec des données stubbées
DbContextInitializer.Seed(db);
}
using (AlbumArtisteDBEntities db = new AlbumArtisteDBEntities())
{
WriteLine("Albums : ");
foreach (var album in db.Albums)
foreach (var album in db.Albums.Include(a => a.AlbumsArtistes).ThenInclude(aa => aa.Artiste))
{
WriteLine($"\t{album.UniqueId}: {album.Titre} (sorti le : {album.DateDeSortie.ToString("d")})");
foreach (var artiste in album.Artistes)
@ -47,7 +51,7 @@ namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
WriteLine();
WriteLine("Artistes :");
foreach (var artiste in db.Artistes)
foreach (var artiste in db.Artistes.Include(a => a.AlbumsArtistes).ThenInclude(aa => aa.Album))
{
var annéeDeMort = artiste.DateDeMort.HasValue ? $" - {artiste.DateDeMort.Value.Year}" : "";
var titresAlbums = artiste.Albums.Aggregate(String.Empty, (albums, album) => albums + $"\"{album.Titre}\" ");

@ -9,7 +9,7 @@
//
// ========================================================================
namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
namespace ex_042_012_EF_CF_Many_to_Many_procurators
{
/// <summary>
/// table permettant de réaliser la table d'association

@ -12,7 +12,7 @@
using Microsoft.EntityFrameworkCore;
using System;
namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
namespace ex_042_012_EF_CF_Many_to_Many_procurators
{
/// <summary>
/// La classe qui dérive de DbContext est celle qui permettra de faire les opérations CRUD sur le modèle.
@ -25,7 +25,7 @@ namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=ex_042_011_EF_CF_Many_to_Many_FluentAPI.mdf;Trusted_Connection=True;");
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=ex_042_012_EF_CF_Many_to_Many_procurators.mdf;Trusted_Connection=True;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
@ -54,13 +54,12 @@ namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
//modelBuilder.Entity<AlbumEF>().Property<Guid>("AlbumId");
//modelBuilder.Entity<ArtisteEF>().Property<Guid>("ArtisteId");
modelBuilder.Entity<ArtisteEF>().Ignore(a => a.Albums);
modelBuilder.Entity<AlbumEF>().Ignore(a => a.Artistes);
//crée une clé primaire à partir des deux propriétés précédentes
modelBuilder.Entity<AlbumArtiste>().HasKey("AlbumId", "ArtisteId");
//on demande au modèle d'ignorer les propriétés Artistes et Albums d'AlbumEF et ArtisteEF
modelBuilder.Entity<AlbumEF>().Ignore("Artistes").Ignore("Album");
modelBuilder.Entity<ArtisteEF>().Ignore("Albums").Ignore("Artiste");
//lie l'entité AlbumArtiste à l'entité Album
modelBuilder.Entity<AlbumArtiste>()
.HasOne(aa => aa.Album)

@ -13,110 +13,24 @@ using System;
using System.Collections.Generic;
using System.Linq;
namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
namespace ex_042_012_EF_CF_Many_to_Many_procurators
{
/// <summary>
/// procurateur pour la classe Album
/// </summary>
public class AlbumEF : IAlbum
public class AlbumEF : Album
{
/// <summary>
/// le sujet réel wrappé par le procurateur
/// lorsqu'il est setté, la collection d'artistes est mise à jour
/// </summary>
private Album Album
{
get
{
return album;
}
set
{
album = value;
//UpdateArtistes();
}
}
private Album album;
/// <summary>
/// collection d'AlbumArtiste pour le lien avec la table d'association
/// </summary>
public ICollection<AlbumArtiste> AlbumsArtistes
{
get
{
return albumsArtistes;
}
set
{
albumsArtistes = value;
//UpdateArtistes();
}
}
private ICollection<AlbumArtiste> albumsArtistes = new List<AlbumArtiste>();
//private void UpdateArtistes()
//{
// if (Album != null && AlbumsArtistes != null)
// {
// foreach (var art in AlbumsArtistes.Select(aa => aa.Artiste.Artiste))
// {
// Album.Artistes.Add(art);
// }
// }
//}
public ICollection<AlbumArtiste> AlbumsArtistes { get; set; } = new List<AlbumArtiste>();
public ICollection<IArtiste> Artistes
public new ICollection<IArtiste> Artistes
{
get
{
return AlbumsArtistes.Select<AlbumArtiste, IArtiste>(aa => aa.Artiste).ToList();
}
}
public DateTime DateDeSortie
{
get
{
return Album.DateDeSortie;
}
set
{
Album.DateDeSortie = value;
}
}
public string Titre
{
get
{
return Album.Titre;
}
set
{
Album.Titre = value;
}
}
//private Guid uniqueId;
public Guid UniqueId
{
//get { return uniqueId; }
get => Album.UniqueId;
//set { uniqueId = value; Album.UniqueId = value; }
set => Album.UniqueId = value;
}
public AlbumEF()
{
Album = new Album();
}
public AlbumEF(Album album)
{
Album = album;
}
}
}

@ -13,14 +13,14 @@ using System;
using System.Collections.Generic;
using System.Linq;
namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
namespace ex_042_012_EF_CF_Many_to_Many_procurators
{
/// <summary>
/// procurateur pour la classe Artiste
/// </summary>
public class ArtisteEF : IArtiste
public class ArtisteEF : Artiste
{
public ICollection<IAlbum> Albums
public new ICollection<IAlbum> Albums
{
get
{
@ -28,112 +28,6 @@ namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
}
}
public ICollection<AlbumArtiste> ArtistesAlbums
{
get
{
return artistesAlbums;
}
set
{
artistesAlbums = value;
//UpdateAlbums();
}
}
private ICollection<AlbumArtiste> artistesAlbums = new List<AlbumArtiste>();
private Artiste Artiste
{
get
{
return artiste;
}
set
{
artiste = value;
//UpdateAlbums();
}
}
private Artiste artiste;
//private void UpdateAlbums()
//{
// if (Artiste != null && ArtistesAlbums != null)
// {
// foreach (var alb in ArtistesAlbums.Select(aa => aa.Album.Album))
// {
// Artiste.Albums.Add(alb);
// }
// }
//}
public DateTime? DateDeMort
{
get
{
return Artiste.DateDeMort;
}
set
{
Artiste.DateDeMort = value;
}
}
public DateTime DateDeNaissance
{
get
{
return Artiste.DateDeNaissance;
}
set
{
Artiste.DateDeNaissance = value;
}
}
public string Nom
{
get
{
return Artiste.Nom;
}
set
{
Artiste.Nom = value;
}
}
public string Prénom
{
get
{
return Artiste.Prénom;
}
set
{
Artiste.Prénom = value;
}
}
//private Guid uniqueId;
public Guid UniqueId
{
//get { return uniqueId; }
get => Artiste.UniqueId;
//set { uniqueId = value; Artiste.UniqueId = value; }
set => Artiste.UniqueId = value;
}
public ArtisteEF()
{
Artiste = new Artiste();
}
public ArtisteEF(Artiste artiste)
{
Artiste = artiste;
}
public ICollection<AlbumArtiste> ArtistesAlbums { get; set; } = new List<AlbumArtiste>();
}
}

@ -14,7 +14,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
namespace ex_042_012_EF_CF_Many_to_Many_procurators
{
/// <summary>
/// initialiseur de stratégies...
@ -36,8 +36,8 @@ namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
static void AddArtisteAlbum(AlbumArtisteDBEntities context, string album, string artiste)
{
//met à jour les liens entre album et artiste
albums[album].Artistes.Add(artistes[artiste]);
artistes[artiste].Albums.Add(albums[album]);
//albums[album].Artistes.Add(artistes[artiste]);
//artistes[artiste].Albums.Add(albums[album]);
//récupère les procurateurs sur les album et artiste concernés
AlbumEF albumEF = albumsEF[album];
@ -59,27 +59,27 @@ namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
{
SetInitializer(context, InitializationStrategies.DropCreateDatabaseAlways);
albums = new Dictionary<string, Album>()
albumsEF = new Dictionary<string, AlbumEF>()
{
["kindOfBlue"] = new Album { Titre = "Kind of Blue", DateDeSortie = new DateTime(1959, 8, 17) },
["somethinElse"] = new Album { Titre = "Somethin' Else", DateDeSortie = new DateTime(1958, 8, 1) }
["kindOfBlue"] = new AlbumEF { Titre = "Kind of Blue", DateDeSortie = new DateTime(1959, 8, 17) },
["somethinElse"] = new AlbumEF { Titre = "Somethin' Else", DateDeSortie = new DateTime(1958, 8, 1) }
};
artistes = new Dictionary<string, Artiste>()
artistesEF = new Dictionary<string, ArtisteEF>()
{
["milesDavis"] = new Artiste { Prénom = "Miles", Nom = "Davis", DateDeNaissance = new DateTime(1926, 5, 26), DateDeMort = new DateTime(1991, 9, 28) },
["johnColtrane"] = new Artiste { Prénom = "John", Nom = "Coltrane", DateDeNaissance = new DateTime(1926, 9, 23), DateDeMort = new DateTime(1967, 7, 11) },
["julianAdderley"] = new Artiste { Prénom = "Julian", Nom = "Adderley", DateDeNaissance = new DateTime(1928, 9, 15), DateDeMort = new DateTime(1975, 8, 8) },
["billEvans"] = new Artiste { Prénom = "Bill", Nom = "Evans", DateDeNaissance = new DateTime(1929, 8, 16), DateDeMort = new DateTime(1980, 9, 15) },
["wyntonKelly"] = new Artiste { Prénom = "Wynton", Nom = "Kelly", DateDeNaissance = new DateTime(1931, 12, 2), DateDeMort = new DateTime(1971, 4, 12) },
["paulChambers"] = new Artiste { Prénom = "Paul", Nom = "Chambers", DateDeNaissance = new DateTime(1935, 4, 22), DateDeMort = new DateTime(1969, 1, 4) },
["jimmyCobb"] = new Artiste { Prénom = "Jimmy", Nom = "Cobb", DateDeNaissance = new DateTime(1929, 1, 20) },
["hankJones"] = new Artiste { Prénom = "Hank", Nom = "Jones", DateDeNaissance = new DateTime(1918, 7, 31), DateDeMort = new DateTime(2010, 5, 16) },
["samJones"] = new Artiste { Prénom = "Sam", Nom = "Jones", DateDeNaissance = new DateTime(1924, 11, 12), DateDeMort = new DateTime(1981, 12, 15) },
["artBlakey"] = new Artiste { Prénom = "Art", Nom = "Blakey", DateDeNaissance = new DateTime(1919, 10, 11), DateDeMort = new DateTime(1990, 10, 16) }
["milesDavis"] = new ArtisteEF { Prénom = "Miles", Nom = "Davis", DateDeNaissance = new DateTime(1926, 5, 26), DateDeMort = new DateTime(1991, 9, 28) },
["johnColtrane"] = new ArtisteEF { Prénom = "John", Nom = "Coltrane", DateDeNaissance = new DateTime(1926, 9, 23), DateDeMort = new DateTime(1967, 7, 11) },
["julianAdderley"] = new ArtisteEF { Prénom = "Julian", Nom = "Adderley", DateDeNaissance = new DateTime(1928, 9, 15), DateDeMort = new DateTime(1975, 8, 8) },
["billEvans"] = new ArtisteEF { Prénom = "Bill", Nom = "Evans", DateDeNaissance = new DateTime(1929, 8, 16), DateDeMort = new DateTime(1980, 9, 15) },
["wyntonKelly"] = new ArtisteEF { Prénom = "Wynton", Nom = "Kelly", DateDeNaissance = new DateTime(1931, 12, 2), DateDeMort = new DateTime(1971, 4, 12) },
["paulChambers"] = new ArtisteEF { Prénom = "Paul", Nom = "Chambers", DateDeNaissance = new DateTime(1935, 4, 22), DateDeMort = new DateTime(1969, 1, 4) },
["jimmyCobb"] = new ArtisteEF { Prénom = "Jimmy", Nom = "Cobb", DateDeNaissance = new DateTime(1929, 1, 20) },
["hankJones"] = new ArtisteEF { Prénom = "Hank", Nom = "Jones", DateDeNaissance = new DateTime(1918, 7, 31), DateDeMort = new DateTime(2010, 5, 16) },
["samJones"] = new ArtisteEF { Prénom = "Sam", Nom = "Jones", DateDeNaissance = new DateTime(1924, 11, 12), DateDeMort = new DateTime(1981, 12, 15) },
["artBlakey"] = new ArtisteEF { Prénom = "Art", Nom = "Blakey", DateDeNaissance = new DateTime(1919, 10, 11), DateDeMort = new DateTime(1990, 10, 16) }
};
albumsEF = albums.ToDictionary(kvp => kvp.Key, kvp => new AlbumEF(kvp.Value));
artistesEF = artistes.ToDictionary(kvp => kvp.Key, kvp => new ArtisteEF(kvp.Value));
//albumsEF = albums.ToDictionary(kvp => kvp.Key, kvp => new AlbumEF(kvp.Value));
//artistesEF = artistes.ToDictionary(kvp => kvp.Key, kvp => new ArtisteEF(kvp.Value));
//les artistes qui jouent sur Kind Of Blue sont reliés à l'album
AddArtisteAlbum(context, "kindOfBlue", "milesDavis");

@ -13,7 +13,7 @@
using System;
using System.Collections.Generic;
namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
namespace ex_042_012_EF_CF_Many_to_Many_procurators
{
/// <summary>
/// Album est une classe POCO, i.e. Plain Old CLR Object.

@ -16,7 +16,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
namespace ex_042_012_EF_CF_Many_to_Many_procurators
{
/// <summary>
/// Artiste est une classe POCO, i.e. Plain Old CLR Object.

@ -12,7 +12,7 @@
using System;
using System.Collections.Generic;
namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
namespace ex_042_012_EF_CF_Many_to_Many_procurators
{
/// <summary>
/// façade immuable et couche abstraite commune pour le Model et le procurateur

@ -12,7 +12,7 @@
using System;
using System.Collections.Generic;
namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
namespace ex_042_012_EF_CF_Many_to_Many_procurators
{
/// <summary>
/// façade immuable et couche abstraite commune pour le Model et le procurateur

@ -5,7 +5,7 @@ using System.Linq;
using System.Threading.Tasks;
using static System.Console;
namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
namespace ex_042_012_EF_CF_Many_to_Many_procurators
{
public class Program
{
@ -49,12 +49,12 @@ namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
DbContextInitializer.Seed(db);
}
using (AlbumArtisteDBEntities db = new AlbumArtisteDBEntities())
{
{
WriteLine("Albums : ");
foreach (var album in db.Albums)
foreach (var album in db.Albums.Include(a => a.AlbumsArtistes).ThenInclude(aa => aa.Artiste))
{
WriteLine($"\t{album.UniqueId}: {album.Titre} (sorti le : {album.DateDeSortie.ToString("d")})");
WriteLine($"\t{album.UniqueId}: {album.Titre} (sorti le : {album.DateDeSortie.ToString("d")})\n");
foreach (var artiste in album.Artistes)
{
WriteLine($"\t\t{artiste.Prénom} {artiste.Nom}");
@ -64,13 +64,23 @@ namespace ex_042_011_EF_CF_Many_to_Many_FluentAPI
WriteLine();
WriteLine("Artistes :");
foreach (var artiste in db.Artistes.Include(a => a.ArtistesAlbums))
foreach (var artiste in db.Artistes.Include(a => a.ArtistesAlbums).ThenInclude(aa => aa.Album))
{
var annéeDeMort = artiste.DateDeMort.HasValue ? $" - {artiste.DateDeMort.Value.Year}" : "";
var titresAlbums = artiste.Albums.Aggregate(String.Empty, (albums, album) => albums + $"\"{album.Titre}\" ");
WriteLine($"\t{artiste.UniqueId}: {artiste.Prénom} {artiste.Nom} ({artiste.DateDeNaissance.Year}{annéeDeMort}) (albums: {titresAlbums})");
}
//WriteLine("Albums : ");
//foreach (var album in db.Albums.Include(a => a.AlbumsArtistes))
//{
// WriteLine($"\t{album.UniqueId}: {album.Titre} (sorti le : {album.DateDeSortie.ToString("d")})");
// foreach (var artiste in album.Artistes)
// {
// WriteLine($"\t\t{artiste.Prénom} {artiste.Nom}");
// }
//}
}
}
catch (NotImplementedException exception)

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AssemblyName>ex_042_011_EF_CF_Many_to_Many_FluentAPI</AssemblyName>
<AssemblyName>ex_042_012_EF_CF_Many_to_Many_procurators</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>ex_042_011_EF_CF_Many_to_Many_FluentAPI</PackageId>
<PackageId>ex_042_012_EF_CF_Many_to_Many_procurators</PackageId>
<RuntimeFrameworkVersion>3.0.1</RuntimeFrameworkVersion>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
Loading…
Cancel
Save