diff --git a/src/DbContextLib/HeartTrackContext.cs b/src/DbContextLib/HeartTrackContext.cs index 919007b..5dbb584 100644 --- a/src/DbContextLib/HeartTrackContext.cs +++ b/src/DbContextLib/HeartTrackContext.cs @@ -8,7 +8,7 @@ using Entities; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Migrations.Operations; + namespace DbContextLib { diff --git a/src/Entities/FriendshipEntity.cs b/src/Entities/FriendshipEntity.cs index fb7446f..6fadb15 100644 --- a/src/Entities/FriendshipEntity.cs +++ b/src/Entities/FriendshipEntity.cs @@ -6,9 +6,9 @@ public class FriendshipEntity { [ForeignKey("FollowingId")] public int FollowingId { get; set; } - public AthleteEntity Following { get; set; } + public AthleteEntity Following { get; set; } = null!; [ForeignKey("FollowerId")] public int FollowerId { get; set; } - public AthleteEntity Follower { get; set; } + public AthleteEntity Follower { get; set; } = null!; public DateTime StartDate { get; set; } } \ No newline at end of file diff --git a/src/Entities/Picture.cs b/src/Entities/Picture.cs index 53ab376..61ebedb 100644 --- a/src/Entities/Picture.cs +++ b/src/Entities/Picture.cs @@ -2,10 +2,8 @@ using System.ComponentModel.DataAnnotations; public class Picture { - [Key] public Guid Id { get; set; } [Required] - public byte[] Bytes { get; set; } - + public byte[] Bytes { get; set; } = null!; } \ No newline at end of file diff --git a/src/Model2Entities/ActivityRepository.cs b/src/Model2Entities/ActivityRepository.cs index 7d1b1a4..f879b17 100644 --- a/src/Model2Entities/ActivityRepository.cs +++ b/src/Model2Entities/ActivityRepository.cs @@ -15,6 +15,21 @@ public partial class DbDataManager public async Task> GetItems(int index, int count, Enum? orderingProperty = null, bool descending = false) { + // public class MyLogger + // { + // public void Log(string component, string message) + // { + // Console.WriteLine("Component: {0} Message: {1} ", component, message); + // } + // } + // ? Utilisation du logger !!! + //! using (var context = new LibraryContext()) + //! { + // var logger = new MyLogger(); + // context.Database.Log = s => logger.Log("EFApp", s); + //! // log la connexion à la base de donnée + //! context.Database.Log = Console.Write; + //! } throw new NotImplementedException(); } diff --git a/src/Model2Entities/Extension.cs b/src/Model2Entities/Extension.cs new file mode 100644 index 0000000..d404f58 --- /dev/null +++ b/src/Model2Entities/Extension.cs @@ -0,0 +1,27 @@ +// using System; +// using Entities; +// using Models; + +// namespace Model2Entities +// { +// public static class Extension +// { +// public static TEntity ToEntity(this Book model) +// => new BookEntity +// { +// Id = model.Id, +// Title = model.Title, +// Author = model.Author, +// Isbn = model.Isbn +// }; + +// public static IEnumerable ToEntities(this IEnumerable models) +// => models.Select(m => m.ToEntity()); + +// public static Book ToModel(this TEntity myBookEntity) +// => new Book(myBookEntity.Id, myBookEntity.Title, myBookEntity.Author, myBookEntity.Isbn); + +// public static IEnumerable ToModels(this IEnumerable booksEntities) +// => booksEntities.Select(e => e.ToModel()); +// } +// } \ No newline at end of file diff --git a/src/Tests/ConsoleTestRelationships/Program.cs b/src/Tests/ConsoleTestRelationships/Program.cs index 6589076..36dad0c 100644 --- a/src/Tests/ConsoleTestRelationships/Program.cs +++ b/src/Tests/ConsoleTestRelationships/Program.cs @@ -1,5 +1,6 @@  using DbContextLib; +using Entities; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; @@ -274,41 +275,6 @@ class Program Console.WriteLine($""); Console.WriteLine($"\t\t{athlete.Followers.Aggregate("", (seed, kvp) => $"{seed} [{kvp.FollowerId} ; {kvp.FollowingId} ; {kvp.StartDate.ToString("dd/MM/yyyy hh:mm:ss")}]")}"); - - // Console.WriteLine("\t\tFollowers :"); - // Console.WriteLine("\t\t---------------------------------"); - - // foreach (var followers in athlete.Followers) - // { - // Console.WriteLine($"\t\t\t{followers.IdAthlete} - {followers.FirstName}, {followers.LastName}, {followers.DateOfBirth}, {followers.Sexe}, {followers.Weight}, {followers.IsCoach}"); - // } - - // Console.WriteLine("\t\tFollowings :"); - // Console.WriteLine("\t\t---------------------------------"); - - // foreach (var following in athlete.Followings) - // { - // // Console.WriteLine($"\t\t{following.Followings.Aggregate("", (seed, kvp) => $"{seed} [{kvp.ArtistEntityId} ; {kvp.CreatedOn.ToString("dd/MM/yyyy hh:mm:ss")}]")}"); - // Console.WriteLine($"\t\t\t{following.IdAthlete} - {following.FirstName}, {following.LastName}, {following.DateOfBirth}, {following.Sexe}, {following.Weight}, {following.IsCoach}"); - // } - - // using (MyDbContext db = new MyDbContext()) - // { - // WriteLine("Content of database (albums) : "); - // foreach (var al in db.Albums.Include(a => a.Artists)) - // { - // WriteLine($"\t{al}"); - // WriteLine($"\t\t{al.AlbumArtists.Aggregate("", (seed, kvp) => $"{seed} [{kvp.ArtistEntityId} ; {kvp.CreatedOn.ToString("dd/MM/yyyy hh:mm:ss")}]")}"); - // } - - // WriteLine("Content of database (artists) : "); - // foreach (var ar in db.Artists) - // { - // WriteLine($"\t{ar}"); - // WriteLine($"\t\t{ar.ArtistAlbums.Aggregate("", (seed, kvp) => $"{seed} [{kvp.AlbumEntityId} ; {kvp.CreatedOn.ToString("dd/MM/yyyy hh:mm:ss")}]")}"); - // } - // } } } - } \ No newline at end of file diff --git a/src/Tests/ConsoleTestRelationships/uca.HeartTrack.db b/src/Tests/ConsoleTestRelationships/uca.HeartTrack.db new file mode 100644 index 0000000..bde4d91 Binary files /dev/null and b/src/Tests/ConsoleTestRelationships/uca.HeartTrack.db differ