FreeSQL连接MySQL
安装 FeeSql相关库
FreeSql 基本库
FreeSql.DbContext
FreeSql.Extensions.Linq linq语法扩展库
FreeSql.Provider.Mysql MySQL连接库
新建DbConent.cs
public class Base
{
static string connstr = @"Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;SslMode=none;Initial Catalog=sales;CharSet=utf8mb4";
public static readonly IFreeSql db = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.MySql, connstr)
.UseAutoSyncStructure(true)
.Build();
public class DBContext : DbContext
{
public DbSet<Users> Users { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder builder)
{
var sql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.MySql, connstr)
.UseAutoSyncStructure(true)
.Build();
builder.UseFreeSql(sql);
}
}
}