Implemented EF Core Migrations #13

This commit is contained in:
amazing-username
2019-04-14 23:12:18 +00:00
parent 0c47da3665
commit cb6e737bff
2 changed files with 16 additions and 7 deletions
+5 -6
View File
@@ -14,15 +14,14 @@ namespace Icarus.Models.Context
{ {
public DbSet<Song> Songs { get; set; } public DbSet<Song> Songs { get; set; }
public SongContext(DbContextOptions<SongContext> options)
: base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
modelBuilder.Entity<Song>(); modelBuilder.Entity<Song>();
} }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySQL("server=;database=;user=;password=");
}
} }
} }
+11 -1
View File
@@ -11,8 +11,13 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Microsoft.EntityFrameworkCore;
using MySql.Data;
using MySql.Data.EntityFrameworkCore.Extensions;
using MySql.Data.MySqlClient;
using Icarus.Models; using Icarus.Models;
using Icarus.Models.Context;
namespace Icarus namespace Icarus
{ {
@@ -30,8 +35,13 @@ namespace Icarus
{ {
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSingleton<IConfiguration>(Configuration); services.AddSingleton<IConfiguration>(Configuration);
var connString = Configuration.GetConnectionString("DefaultConnection");
services.Add(new ServiceDescriptor(typeof(MusicStoreContext), new MusicStoreContext(Configuration.GetConnectionString("DefaultConnection")))); services.Add(new ServiceDescriptor(typeof(MusicStoreContext),
new MusicStoreContext(Configuration
.GetConnectionString("DefaultConnection"))));
services.AddDbContext<SongContext>(options => options.UseMySQL(connString));
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.