前言
GZY.EFCoreCompare 是一个用于 对比数据库结构和 EF Core 代码中的 DbContext 的库。
它基于 EF Core 的 Scaffolding 机制,生成 DatabaseModel
(从数据库提取的模型),
并与代码中的 DbContext
进行比对,从而找出两者之间的差异。
开源项目地址:GZY.EFCoreCompare
欢迎start和提issues
主要用途
DatabaseModel
)。DbContext
及其 EntityType
实体定义。对比流程
DatabaseModel
。DbContext
DbContext
及其实体。使用方式
直接在项目中通过Nuget引用GZY.EFCoreCompare.Core
与对应数据库的驱动库,例:GZY.EFCoreCompare.MySql
库中,比对代码如下:
var compareEFcore= new CompareEFCore();
compareEFcore.CompareEfWithDbAsync(YourDbContext);
GZY.EFCoreCompare.UI
与对应的数据库驱动,例如:GZY.EFCoreCompare.MySql
builder.Services.AddDbContext<TestDbContext>(options =>
{
string connStr = "";
options.UseMySql(connStr, new MySqlServerVersion(new Version(8, 0, 20)), builder => {
builder.SchemaBehavior(MySqlSchemaBehavior.Ignore);
});
}); //注入EFDbContext
builder.Services.AddEFCoreCompareUI(new CompareEFCoreConfig { CaseComparer=StringComparer.CurrentCultureIgnoreCase}); //需放在AddDbContext之后
app.UseEFCoreCompareUI(); //添加UI界面
http://localhost:5130/DBCompareUI
, /DBCompareUI
为UI的界面地址