aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadevchavali1@gmail.com>2019-02-08 11:48:44 +0000
committerAryadev Chavali <aryadevchavali1@gmail.com>2019-02-08 11:48:44 +0000
commitf714e54dba371f7398aecbff824f73d529d038f0 (patch)
treec3efd8b36ccbc258777b9d544a161b12720afc9d
parent455f08cf719995ad583b661cdbad00cc1dc1c10b (diff)
downloadnewsaggregator-f714e54dba371f7398aecbff824f73d529d038f0.tar.gz
newsaggregator-f714e54dba371f7398aecbff824f73d529d038f0.tar.bz2
newsaggregator-f714e54dba371f7398aecbff824f73d529d038f0.zip
Used scaffolding to get Database object
-rw-r--r--Database/Database.cs136
1 files changed, 110 insertions, 26 deletions
diff --git a/Database/Database.cs b/Database/Database.cs
index 551ca5d..100a9af 100644
--- a/Database/Database.cs
+++ b/Database/Database.cs
@@ -1,26 +1,110 @@
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Collections.Generic;
-
-
-using Microsoft.EntityFrameworkCore;
-using MySql.Data.EntityFrameworkCore;
-
-using Classes;
-
-namespace Database {
- public class DatabaseContext : DbContext {
- public DatabaseContext() {
- Details = Task.Run(async () => await DetailsHelper.GetDetails()).GetAwaiter().GetResult();
- }
- public DbSet<Article> Articles;
- public DbSet<Config> Configs;
- public Dictionary<string, string> Details;
-
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
- base.OnConfiguring(optionsBuilder);
- optionsBuilder.UseMySQL($"server=localhost;port=3306;user={Details["username"]};password={Details["password"]};database={Details["database"]}");
- }
- }
-}
+using System;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Classes;
+
+namespace Database.Database {
+ public partial class DatabaseContext : DbContext {
+ private Dictionary<string, string> Details;
+
+ public DatabaseContext() {
+ Details = Task.Run(async () => await DetailsHelper.GetDetails()).GetAwaiter().GetResult();
+ }
+
+ public DatabaseContext(DbContextOptions<DatabaseContext> options)
+ : base(options) {
+ Details = Task.Run(async () => await DetailsHelper.GetDetails()).GetAwaiter().GetResult();
+ }
+
+ public virtual DbSet<Article> Articles { get; set; }
+ public virtual DbSet<Config> Configs { get; set; }
+
+ 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 OnModelCreating(ModelBuilder modelBuilder) {
+ modelBuilder.HasAnnotation("ProductVersion", "2.2.1-servicing-10028");
+
+ modelBuilder.Entity<Article>(entity => {
+ entity.HasKey(e => e.ArticleID);
+
+ entity.ToTable("articles", "news_aggregator");
+
+ entity.Property(e => e.ArticleID)
+ .HasColumnName("article_id")
+ .HasColumnType("int(11)")
+ .ValueGeneratedNever();
+
+ entity.Property(e => e.ArticleLink)
+ .HasColumnName("article_link")
+ .HasMaxLength(64)
+ .IsUnicode(false);
+
+ entity.Property(e => e.Description)
+ .HasColumnName("description")
+ .HasMaxLength(255)
+ .IsUnicode(false);
+
+ entity.Property(e => e.ImageLink)
+ .HasColumnName("image_link")
+ .HasMaxLength(128)
+ .IsUnicode(false);
+
+ entity.Property(e => e.PublishDate)
+ .HasColumnName("publish_date")
+ .HasColumnType("date");
+
+ entity.Property(e => e.Source)
+ .HasColumnName("source")
+ .HasMaxLength(8)
+ .IsUnicode(false);
+
+ entity.Property(e => e.Title)
+ .HasColumnName("title")
+ .HasMaxLength(255)
+ .IsUnicode(false);
+ });
+
+ modelBuilder.Entity<Config>(entity => {
+ entity.HasKey(e => e.ConfigID);
+
+ entity.ToTable("configs", "news_aggregator");
+
+ entity.Property(e => e.ConfigID)
+ .HasColumnName("config_id")
+ .HasColumnType("int(11)")
+ .ValueGeneratedNever();
+
+ entity.Property(e => e.ArticleLink)
+ .HasColumnName("article_link")
+ .HasColumnType("int(11)");
+
+ entity.Property(e => e.Description)
+ .HasColumnName("description")
+ .HasColumnType("int(11)");
+
+ entity.Property(e => e.ImageLink)
+ .HasColumnName("image_link")
+ .HasColumnType("int(11)");
+
+ entity.Property(e => e.PublishDate)
+ .HasColumnName("publish_date")
+ .HasColumnType("int(11)");
+
+ entity.Property(e => e.Source)
+ .HasColumnName("source")
+ .HasColumnType("int(11)");
+
+ entity.Property(e => e.Title)
+ .HasColumnName("title")
+ .HasColumnType("int(11)");
+ });
+ }
+ }
+}