# KnownDB **Repository Path**: known/known-db ## Basic Information - **Project Name**: KnownDB - **Description**: Known框架数据访问支持的第三方提供者,支持SqlSugar、EFCore、FreeSql。 - **Primary Language**: C# - **License**: MIT - **Default Branch**: master - **Homepage**: http://known.org.cn - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 3 - **Created**: 2024-09-25 - **Last Updated**: 2025-07-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # KnownDB #### 介绍 `KnownDB`是`Known`框架数据访问支持的第三方提供者,支持`SqlSugar`、`EntityFramework`、`FreeSql`。 #### 安装教程 在后端项目中引用如下三种方案之一: ``` xml ``` #### 使用说明 在`Program.cs`中添加如下代码: ``` csharp // SqlSugar配置 builder.Services.AddKnownSqlSugar(config => { config.DbType = DbType.SqlServer; config.ConnectionString = builder.Configuration.GetSection("ConnString").Get(); config.IsAutoCloseConnection = true; config.MoreSettings ??= new ConnMoreSettings(); config.MoreSettings.IsAutoToUpper = false; config.AopEvents ??= new AopEvents(); config.AopEvents.OnLogExecuting = (sql, pars) => { //var param = string.Join(",", pars.Select(p => $"{p.ParameterName}={p.Value}")); //Console.WriteLine($"SQL: {sql}"); //Console.WriteLine($"参数: {param}"); }; }); // EntityFramework配置 builder.Services.AddKnownEntityFramework(option => { // 配置数据库 option.OnConfig = c => c.UseSqlServer(builder.Configuration.GetSection("ConnString").Get()); // 在此配置业务库数据模型 //option.OnModel = m => m.Entity(); }); // FreeSql配置 builder.Services.AddKnownFreeSql(option => { option.UseConnectionString(DataType.SqlServer, builder.Configuration.GetSection("ConnString").Get()) .UseMonitorCommand(cmd => Console.WriteLine($"Sql:{cmd.CommandText}")) .UseAutoSyncStructure(true); //自动同步实体结构到数据库,只有CRUD时才会生成表 }); ```