2021-06-22 16:00:20 +10:00
|
|
|
|
using MvcMusicStore.Models;
|
|
|
|
|
using System;
|
2021-06-22 15:57:09 +10:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data.Entity;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
|
|
|
|
namespace MvcMusicStore.Data
|
|
|
|
|
{
|
|
|
|
|
public class MusicStoreDB : DbContext
|
|
|
|
|
{
|
|
|
|
|
// You can add custom code to this file. Changes will not be overwritten.
|
|
|
|
|
//
|
|
|
|
|
// If you want Entity Framework to drop and regenerate your database
|
|
|
|
|
// automatically whenever you change your model schema, please use data migrations.
|
|
|
|
|
// For more information refer to the documentation:
|
|
|
|
|
// http://msdn.microsoft.com/en-us/data/jj591621.aspx
|
|
|
|
|
|
|
|
|
|
public MusicStoreDB() : base("name=MusicStoreDB")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public System.Data.Entity.DbSet<MvcMusicStore.Models.Album> Albums { get; set; }
|
|
|
|
|
|
|
|
|
|
public System.Data.Entity.DbSet<MvcMusicStore.Models.Artist> Artists { get; set; }
|
|
|
|
|
|
|
|
|
|
public System.Data.Entity.DbSet<MvcMusicStore.Models.Genre> Genres { get; set; }
|
|
|
|
|
}
|
2021-06-22 16:00:20 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class MusicStoreDbInitializer
|
|
|
|
|
: DropCreateDatabaseAlways<MusicStoreDB>
|
|
|
|
|
{
|
|
|
|
|
protected override void Seed(MusicStoreDB context)
|
|
|
|
|
{
|
|
|
|
|
context.Artists.Add(new Artist { Name = "Al Di Meola" });
|
|
|
|
|
|
|
|
|
|
context.Genres.Add(new Genre { Name = "Jazz" });
|
|
|
|
|
|
|
|
|
|
context.Albums.Add(new Album
|
|
|
|
|
{
|
|
|
|
|
Artist = new Artist { Name = "Rush" },
|
|
|
|
|
Genre = new Genre { Name = "Rock" },
|
|
|
|
|
Price = 9.99m,
|
|
|
|
|
Title = "Caravan"
|
|
|
|
|
});
|
|
|
|
|
base.Seed(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-06-22 15:57:09 +10:00
|
|
|
|
}
|