|
|
@ -6,27 +6,32 @@ namespace DbContextLib;
|
|
|
|
|
|
|
|
|
|
|
|
public class LibraryContext : DbContext
|
|
|
|
public class LibraryContext : DbContext
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly StreamWriter LogFile = new StreamWriter("log.txt");
|
|
|
|
|
|
|
|
public LibraryContext()
|
|
|
|
public LibraryContext()
|
|
|
|
: base()
|
|
|
|
: base()
|
|
|
|
{ }
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LibraryContext(DbContextOptions<LibraryContext> options)
|
|
|
|
public LibraryContext(DbContextOptions<LibraryContext> options)
|
|
|
|
: base(options)
|
|
|
|
: base(options)
|
|
|
|
{ }
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DbSet<ArticleEntity> ArticleSet { get; set; }
|
|
|
|
public DbSet<ArticleEntity> ArticleSet { get; set; }
|
|
|
|
public DbSet<UserEntity> UserSet { get; set; }
|
|
|
|
public DbSet<UserEntity> UserSet { get; set; }
|
|
|
|
public DbSet<FormEntity> FormSet { get; set; }
|
|
|
|
public DbSet<FormEntity> FormSet { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public DbSet<ArticleUserEntity> ArticleUserSet { get; set; }
|
|
|
|
public DbSet<ArticleUserEntity> ArticleUserSet { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
optionsBuilder.LogTo(message => LogFile.WriteLine(message), LogLevel.Information);
|
|
|
|
optionsBuilder.LogTo(message =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using var logFile = new StreamWriter("log.txt", append: true);
|
|
|
|
|
|
|
|
logFile.WriteLine(message);
|
|
|
|
|
|
|
|
}, LogLevel.Information);
|
|
|
|
if (!optionsBuilder.IsConfigured)
|
|
|
|
if (!optionsBuilder.IsConfigured)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
optionsBuilder.UseSqlite($"Data Source=Entity_FrameWork.Article.db");
|
|
|
|
optionsBuilder.UseSqlite($"Data Source=Entity_FrameWork.Article.db");
|
|
|
@ -41,12 +46,12 @@ public class LibraryContext : DbContext
|
|
|
|
.HasMany(a => a.Users)
|
|
|
|
.HasMany(a => a.Users)
|
|
|
|
.WithMany(a => a.Articles)
|
|
|
|
.WithMany(a => a.Articles)
|
|
|
|
.UsingEntity<ArticleUserEntity>();
|
|
|
|
.UsingEntity<ArticleUserEntity>();
|
|
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<UserEntity>()
|
|
|
|
modelBuilder.Entity<UserEntity>()
|
|
|
|
.HasMany(u => u.Forms)
|
|
|
|
.HasMany(u => u.Forms)
|
|
|
|
.WithOne(f => f.User)
|
|
|
|
.WithOne(f => f.User)
|
|
|
|
.HasForeignKey(f => f.UserEntityPseudo);
|
|
|
|
.HasForeignKey(f => f.UserEntityPseudo);
|
|
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<FormEntity>()
|
|
|
|
modelBuilder.Entity<FormEntity>()
|
|
|
|
.HasOne(f => f.User)
|
|
|
|
.HasOne(f => f.User)
|
|
|
|
.WithMany(u => u.Forms)
|
|
|
|
.WithMany(u => u.Forms)
|
|
|
@ -80,7 +85,7 @@ public class LibraryContext : DbContext
|
|
|
|
Description = "M&M's new recipe is out and it's the best chocolate ever",
|
|
|
|
Description = "M&M's new recipe is out and it's the best chocolate ever",
|
|
|
|
DatePublished = "2022-02-06",
|
|
|
|
DatePublished = "2022-02-06",
|
|
|
|
LectureTime = 1,
|
|
|
|
LectureTime = 1,
|
|
|
|
Author = "M&M's Red"
|
|
|
|
Author = "M&M's Red"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -107,7 +112,7 @@ public class LibraryContext : DbContext
|
|
|
|
Nom = "Sillard", Prenom = "Noa", Pseudo = "NoaSil", Mail = "", Mdp = "1234", Role = "Admin"
|
|
|
|
Nom = "Sillard", Prenom = "Noa", Pseudo = "NoaSil", Mail = "", Mdp = "1234", Role = "Admin"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<ArticleUserEntity>().HasData(
|
|
|
|
modelBuilder.Entity<ArticleUserEntity>().HasData(
|
|
|
|
new ArticleUserEntity
|
|
|
|
new ArticleUserEntity
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -135,11 +140,11 @@ public class LibraryContext : DbContext
|
|
|
|
UserEntityPseudo = "TomS"
|
|
|
|
UserEntityPseudo = "TomS"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<FormEntity>().HasData(
|
|
|
|
modelBuilder.Entity<FormEntity>().HasData(
|
|
|
|
new FormEntity
|
|
|
|
new FormEntity
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Id = 1,
|
|
|
|
Id = 1,
|
|
|
|
DatePublication = "Form 1 Description",
|
|
|
|
DatePublication = "Form 1 Description",
|
|
|
|
Link = "hhtp://form1.com",
|
|
|
|
Link = "hhtp://form1.com",
|
|
|
|
UserEntityPseudo = "Sha"
|
|
|
|
UserEntityPseudo = "Sha"
|
|
|
@ -161,16 +166,4 @@ public class LibraryContext : DbContext
|
|
|
|
);
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Dispose()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
base.Dispose();
|
|
|
|
|
|
|
|
LogFile.Dispose();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override async ValueTask DisposeAsync()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await base.DisposeAsync();
|
|
|
|
|
|
|
|
await LogFile.DisposeAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|