diff options
author | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-02-10 17:44:35 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-02-10 17:45:18 +0000 |
commit | 6ca611ea71f7201dd9f5c2a685e5d5ad16e62ca1 (patch) | |
tree | 402a42e822aadd8c0e2b3c82ba65f076c81b7dd5 /Database | |
parent | 915ab9c8765fa6478a54be155460a134ccd5f275 (diff) | |
download | newsaggregator-6ca611ea71f7201dd9f5c2a685e5d5ad16e62ca1.tar.gz newsaggregator-6ca611ea71f7201dd9f5c2a685e5d5ad16e62ca1.tar.bz2 newsaggregator-6ca611ea71f7201dd9f5c2a685e5d5ad16e62ca1.zip |
Changed updater - try to get as many articles into the database
Diffstat (limited to 'Database')
-rw-r--r-- | Database/Database.cs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Database/Database.cs b/Database/Database.cs index 6c3511c..2e362af 100644 --- a/Database/Database.cs +++ b/Database/Database.cs @@ -24,12 +24,14 @@ namespace Database { public virtual DbSet<Config> Configs { get; set; } public async Task<int> InsertArticles(IEnumerable<Article> articles) { - try { - await Articles.AddRangeAsync(articles); - return await SaveChangesAsync(); - } catch (Microsoft.EntityFrameworkCore.DbUpdateException) { - return 0; // duplicate title id's + foreach (Article article in articles) { + try { + await Articles.AddAsync(article); + } catch (Microsoft.EntityFrameworkCore.DbUpdateException) { + continue; + } } + return await SaveChangesAsync(); } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { |