コード例 #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcSongContext(serviceProvider.
                                                    GetRequiredService <DbContextOptions <MvcSongContext> >()))
            {
                if (context.Song.Any())
                {
                    return;//song's in the DB. We are good to go.
                }

                context.Song.AddRange(
                    new Song
                {
                    title       = "Don't Stop Believin'",
                    genre       = "Rock",
                    artist      = "Jouney",
                    album       = "Escape",
                    ReleaseDate = DateTime.Parse("1981-3-13")
                },

                    new Song
                {
                    title       = "Thriller'",
                    genre       = "Rock",
                    artist      = "Michael J",
                    album       = "Thriller",
                    ReleaseDate = DateTime.Parse("1981-4-14")
                },

                    new Song
                {
                    title       = "Eye of the Tiger'",
                    genre       = "Rock",
                    artist      = "Survivor",
                    album       = "unknown",
                    ReleaseDate = DateTime.Parse("1985-3-13")
                }
                    );
                context.SaveChanges();
            }
        }
コード例 #2
0
ファイル: SeedData.cs プロジェクト: keshnarana/aspstarter
        public static void Initialize(IServiceProvider serviceProvider)

        {
            using var context = new MvcSongContext(serviceProvider.

                                                   GetRequiredService <DbContextOptions <MvcSongContext> >());



            if (context.Song.Any())
            {
                return;     //songs in the db. Don't do anything We are good to go
            }

            context.Song.AddRange(
                new Song
            {
                title   = "some title",
                release = DateTime.Parse("2020-3-26")
            });
            context.SaveChanges();
        }
コード例 #3
0
 public SongsController(MvcSongContext context)
 {
     _context = context;
 }