数据库
首页 > 数据库> > C#连sqlite

C#连sqlite

作者:互联网

 

创建控制台core3.0版

vs里引入

Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.Sqlite

 

 

一、逆向工程

 

包管理控制台

Scaffold-DbContext ’Data Source=testDb.db’ Microsoft.EntityFrameworkCore.Sqlite

会自动生成文件

    public partial class testDbContext : DbContext
    {
        public testDbContext()
        {
        }

        public testDbContext(DbContextOptions<testDbContext> options)
            : base(options)
        {
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlite("Data Source=testDb.db");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }

 

标签:sqlite,testDbContext,C#,void,Microsoft,EntityFrameworkCore,modelBuilder,public
来源: https://www.cnblogs.com/buchizaodian/p/11946235.html