コード例 #1
0
ファイル: DutchSeeder.cs プロジェクト: adamhimself/DutchApp
        public void Seed()
        {
            _ctx.Database.EnsureCreated();

            if (!_ctx.Verbs.Any())
            {
                // Need to create sample data.
                var filepath          = Path.Combine(_hosting.ContentRootPath, "Data/verbs.json");
                var filepath_auxVerbs = Path.Combine(_hosting.ContentRootPath, "Data/aux_verbs.json");

                var json = File.ReadAllText(filepath);

                var verbs = JsonConvert.DeserializeObject <IEnumerable <Verb> >(json);

                _ctx.Verbs.AddRange(verbs);
                _ctx.SaveChanges();
            }

            if (!_ctx.AuxiliaryVerbs.Any())
            {
                var filepath_auxVerbs = Path.Combine(_hosting.ContentRootPath, "Data/aux_verbs.json");

                var json = File.ReadAllText(filepath_auxVerbs);

                var verbs = JsonConvert.DeserializeObject <IEnumerable <AuxiliaryVerb> >(json);

                _ctx.AuxiliaryVerbs.AddRange(verbs);
                _ctx.SaveChanges();
            }
        }
コード例 #2
0
 public bool SaveAll()
 {
     return(_context.SaveChanges() > 0);
 }