为了账号安全,请及时绑定邮箱和手机立即绑定
关注
Junss

评论数据是怎么更新到数据库的,我在DbInitializer类 Seed方法 加了数据 更新不到数据库中

public static class DbInitializer

    {

        public static void Seed(AppDbContext context)

        {


            if (context.Noodles.Any())

            {

                return;

            }

            context.AddRange(

                new Noodle { Name = "毛细", Price = 12, ShortDescription = "如发丝般细", LongDescription = "如发丝般细如发丝般细", ImageURL = "" },

                new Noodle { Name = "细", Price = 10, ShortDescription = "普通细", LongDescription = "普通细普通细", ImageURL = "" },

                new Noodle { Name = "三细", Price = 11, ShortDescription = "有点粗了", LongDescription = "有点粗了有点粗了", ImageURL = "" }

                );

            context.AddRange(

                new Feedback { Name = "张三", Email = "zhangsan@hotmail.com", CreateDateUTC = DateTime.Now, Message = "味道香" },

                new Feedback { Name = "李四", Email = "lisi@hotmail.com", CreateDateUTC = DateTime.Now, Message = "味道很香" },

                new Feedback { Name = "王五", Email = "wangwu@hotmail.com", CreateDateUTC = DateTime.Now, Message = "味道真香" },

                new Feedback { Name = "赵六", Email = "zhaoliu@hotmail.com", CreateDateUTC = DateTime.Now, Message = "味道贼香" }

                );

            context.SaveChanges();//保存数据库

        }

    }


2020-09-09 源自:打造你的第一个ASP.NET Core... 101 浏览 1 回答

//晓得怎么搞了

if (!context.Feedbacks.Any())

            {

                context.Feedbacks.AddRange(

                new Feedback { Name = "张三", Email = "zhangsan@hotmail.com", CreateDateUTC = DateTime.Now, Message = "味道香" },

                new Feedback { Name = "李四", Email = "lisi@hotmail.com", CreateDateUTC = DateTime.Now, Message = "味道很香" },

                new Feedback { Name = "王五", Email = "wangwu@hotmail.com", CreateDateUTC = DateTime.Now, Message = "味道真香" },

                new Feedback { Name = "赵六", Email = "zhaoliu@hotmail.com", CreateDateUTC = DateTime.Now, Message = "味道贼香" }

               );

                context.SaveChanges();//保存数据库;

            }



2020-09-10
回复 0

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信