# SQLiteCodeFirst **Repository Path**: zhxd19/sqlite-code-first ## Basic Information - **Project Name**: SQLiteCodeFirst - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-06-25 - **Last Updated**: 2024-06-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SQLiteCodeFirst 1、Nuget 安装下面的包 在配置文件中添加 2、在Model类库中建立DbContext:DbContext 在该文件下添加如下代码 public static SQLiteConnection Connection() { SQLiteConnection conn = new SQLiteConnection(); conn.ConnectionString = $@"Data Source={DbPath}"; conn.Open(); return conn; } public MyDbContext() : base(Connection(), false) { } 3、 Enable-Migrations 后在生成的Migrations文件夹下面的Configuration.cs添加如下代码 public Configuration() { AutomaticMigrationsEnabled = false; //出现 下面错误No MigrationSqlGenerator found for provider 'System.Data.SQLite'. Use the SetSqlGenerator method in the target migrations configuration class to register additional SQL generators. //添加下面代码 SetSqlGenerator("System.Data.SQLite", new SQLiteMigrationSqlGenerator()); } 4、Add-Migration update-database 生成的数据库文件在Model文件夹下 问题没有解决!!!应该拷贝的EXE文件夹下