aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Database/Database.cs10
1 files changed, 10 insertions, 0 deletions
diff --git a/Database/Database.cs b/Database/Database.cs
index 75c383f..14569aa 100644
--- a/Database/Database.cs
+++ b/Database/Database.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
@@ -22,6 +23,15 @@ namespace Database {
public virtual DbSet<Article> Articles { get; set; }
public virtual DbSet<Config> Configs { get; set; }
+ public async void InsertArticles(IEnumerable<Article> articles) {
+ try {
+ await Articles.AddRangeAsync(articles);
+ await SaveChangesAsync();
+ } catch (Microsoft.EntityFrameworkCore.DbUpdateException) {
+ return; // duplicate title id's
+ }
+ }
+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
if (!optionsBuilder.IsConfigured) {
optionsBuilder.UseMySQL($"server=localhost;port=3306;user={Details["username"]};password={Details["password"]};database={Details["database"]}");