コード例 #1
0
ファイル: DataGenerator.cs プロジェクト: Pemek/cooking-book
        public static void Initialize(CookingBookContext context)
        {
            if (!context.Recipes.Any())
            {
                var seedDataFile = File.ReadAllText("Resources/SeedData.json");
                var seedDataJson = JObject.Parse(seedDataFile);

                var recipes = JsonConvert.DeserializeObject <List <Recipe> >(seedDataJson["recipes"].ToString());
                context.Recipes.AddRange(recipes);

                context.SaveChanges();
            }
        }