From 3260a181a1d5b282e8fbab20fb511cddf30a3b5e Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 18 Feb 2019 19:02:27 +0000 Subject: Added comments and documentation for database --- Database/Database.cs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'Database') diff --git a/Database/Database.cs b/Database/Database.cs index 035fe84..04c9619 100644 --- a/Database/Database.cs +++ b/Database/Database.cs @@ -8,37 +8,38 @@ using Microsoft.EntityFrameworkCore.Metadata; using Classes; namespace Database { + /// + /// Database context for MySQL + /// public partial class DatabaseContext : DbContext { - private Dictionary Details; - - public DatabaseContext() { - Details = Task.Run(async () => await DetailsHelper.GetDetails()).GetAwaiter().GetResult(); - } + public DatabaseContext() { } public DatabaseContext(DbContextOptions options) - : base(options) { - Details = Task.Run(async () => await DetailsHelper.GetDetails()).GetAwaiter().GetResult(); - } + : base(options) { } public virtual DbSet
Articles { get; set; } + /// + /// Insert multiple articles into database + /// + /// articles to insert public async Task InsertArticles(IEnumerable
articles) { foreach (Article article in articles) { try { await Articles.AddAsync(article); await SaveChangesAsync(); - } catch (Microsoft.EntityFrameworkCore.DbUpdateException) { + } + catch (Microsoft.EntityFrameworkCore.DbUpdateException) { continue; } } } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - if (!optionsBuilder.IsConfigured) { - optionsBuilder.UseMySQL($"server=localhost;port=3306;user={Details["username"]};password={Details["password"]};database={Details["database"]}"); - } - } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { } + /// + /// Model for MySQL database to entity + /// protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.HasAnnotation("ProductVersion", "2.2.1-servicing-10028"); -- cgit v1.2.3-13-gbd6f