diff options
Diffstat (limited to 'Database')
-rw-r--r-- | Database/Database.cs | 29 |
1 files changed, 15 insertions, 14 deletions
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 { + /// <summary> + /// Database context for MySQL + /// </summary> public partial class DatabaseContext : DbContext { - private Dictionary<string, string> Details; - - public DatabaseContext() { - Details = Task.Run(async () => await DetailsHelper.GetDetails()).GetAwaiter().GetResult(); - } + public DatabaseContext() { } public DatabaseContext(DbContextOptions<DatabaseContext> options) - : base(options) { - Details = Task.Run(async () => await DetailsHelper.GetDetails()).GetAwaiter().GetResult(); - } + : base(options) { } public virtual DbSet<Article> Articles { get; set; } + /// <summary> + /// Insert multiple articles into database + /// </summary> + /// <param name="articles">articles to insert</param> public async Task InsertArticles(IEnumerable<Article> 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) { } + /// <summary> + /// Model for MySQL database to entity + /// </summary> protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.HasAnnotation("ProductVersion", "2.2.1-servicing-10028"); |