diff options
author | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-02-18 19:02:27 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-02-18 19:02:27 +0000 |
commit | 3260a181a1d5b282e8fbab20fb511cddf30a3b5e (patch) | |
tree | a7f53f23f62f6a214b3211fbbc74d44c082427b8 /Database/Database.cs | |
parent | 1656a55d32588124a7e176e4fd591faf8599ce39 (diff) | |
download | newsaggregator-3260a181a1d5b282e8fbab20fb511cddf30a3b5e.tar.gz newsaggregator-3260a181a1d5b282e8fbab20fb511cddf30a3b5e.tar.bz2 newsaggregator-3260a181a1d5b282e8fbab20fb511cddf30a3b5e.zip |
Added comments and documentation for database
Diffstat (limited to 'Database/Database.cs')
-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"); |