Cola.EF
3.0.0
dotnet add package Cola.EF --version 3.0.0
NuGet\Install-Package Cola.EF -Version 3.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Cola.EF" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cola.EF" Version="3.0.0" />
<PackageReference Include="Cola.EF" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Cola.EF --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Cola.EF, 3.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Cola.EF@3.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Cola.EF&version=3.0.0
#tool nuget:?package=Cola.EF&version=3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Cola.EF 框架
1. 注入
注入可以通过config配置文件形式注入(推荐)、也可以通过代码直接注入.注入同时会注入IColaUnitOfWork
{
"ColaOrm": {
// TenantType 多租户模式 ConfigId 或者 WithAttr
"TenantType":"ConfigId",
"TenantResolutionStrategy": "NoTenant",
"ColaOrmConfig": [
{
// 多租户模式租户id传参方式
// NoTenant 不使用多租户 RouteValueTenant 路由形式 HttpHeaderTenant http头形式 DomainTenant 域名形式
// 路由形式 和 http头形式 都必须传递 tenantId:value
// 默认值 1
"ConfigId": "1",
"DbType": "MySql",
"ConnectionString": "server=xxx.xxx.xxx.xxx;Database=db;Uid=root;Pwd=pwd;AllowLoadLocalInfile=true;",
"IsAutoCloseConnection": true,
"EnableLogAop": true,
"EnableErrorAop": true,
"EnableGlobalFilter": true
}
]
}
}
// 注入 ColaSqlSugar
builder.Services.AddSingletonColaSqlSugar(config,new HttpContextAccessor(),
tableFilter:(new List<GlobalQueryFilter>()
{
new GlobalQueryFilter()
{
ConfigId = "1",
QueryFilter = (provider => provider.AddTableFilter<IStatus>(t => t.IsDelete == false))
}
}),
aopOnLogExecutingModels:new List<AopOnLogExecutingModel>()
{
new AopOnLogExecutingModel()
{
ConfigId = "1",
AopOnLogExecuting = ((sql, parameters) =>
{
ConsoleHelper.WriteInfo($"sql is\n{sql}");
})
}
},
aopOnErrorModels:new List<AopOnErrorModel>()
{
new AopOnErrorModel()
{
ConfigId = "1",
AopOnError = (ConsoleHelper.WriteException)
}
}
);
var dbClient = builder.Services.BuildServiceProvider().GetService<ISqlSugarRepository>();
var sqlResult = dbClient.GetAll<OdinLog>();
Console.WriteLine(sqlResult.Count);
if (sqlResult.Count > 0)
{
Console.WriteLine(JsonConvert.SerializeObject(sqlResult[0]));
}
如果要使用UnitOfWork
services.AddControllers(options =>
{
// 添加 工作单元过滤器
options.Filters.Add<ColaUnitOfWorkFilter>();
});
并且在action上添加 UnitOfWork 特性
[HttpGet, ColaUnitOfWork]
public async Task<IActionResult> AddTestAsync()
{
}
2. 使用
详见 ConsoleApp1Test
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Cola.Cache (>= 3.0.0)
- Cola.Exception (>= 3.0.0)
- Cola.Models.Core (>= 3.0.0)
- Cola.Utils (>= 3.0.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.0)
- Microsoft.AspNetCore.Routing.Abstractions (>= 2.2.0)
- Microsoft.EntityFrameworkCore (>= 8.0.0)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- SqlSugarCore (>= 5.1.4.146)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.