引用
Microsoft.EntityFrameworkCore.Sqlite
Microsoft.EntityFrameworkCore.Design
使用Navicat
创建sqlite数据库
创建上下文
public class RegionTreeDbContext : DbContext
{
private string connectionString;
public DbSet<RegionTree> Regions { get; set; }
public RegionTreeDbContext(string connectionString)
{
this.connectionString = connectionString;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite(connectionString);
}
}
查询数据
private static string connectionString = @"Data Source=your pathyour db.db";
public void Query()
{
//ef core sqlite 使用
using(RegionTreeDbContext db=new RegionTreeDbContext(connectionString))
{
var region = db.Regions.FirstOrDefault();
}
}