Winform中efcore sqlite

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/adc_god/article/details/81705057

Winform中efcore sqlite

直接上代码
nuget Microsoft.EntityFrameworkCore.Sqlite

        public void Dosomething()
        {

            using (MyContext context = new MyContext())
            {
                context.Database.EnsureCreated();
                //context.Database.Migrate();//后期可以迁移,EnsureCreated 不能改变

                List<User> users = new List<User>();

                for (int i = 40; i < 60; i++)
                {
                    DateTime _n = DateTime.Now;
                    users.Add(new User() { Name = "Dsg" + i ,Time = _n , OAtime = _n.ToOADate() });
                }

                context.AddRange(users);
                context.SaveChanges();

                var t = context.Set_User.Where(p => p.Id < 3).ToList();
                t.ForEach(p => p.IsUpload = false);
                t.ForEach( p=> Console.WriteLine (p));
                context.UpdateRange(t);
                context.SaveChanges();
            }
        }
    }

    public class MyContext : DbContext
    {
        public DbSet<User> Set_User { set; get; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlite("Data Source=MyTest.db");
        }
    }
展开阅读全文

没有更多推荐了,返回首页