DNLiCore_DB 1.0.6
See the version list below for details.
dotnet add package DNLiCore_DB --version 1.0.6
NuGet\Install-Package DNLiCore_DB -Version 1.0.6
<PackageReference Include="DNLiCore_DB" Version="1.0.6" />
paket add DNLiCore_DB --version 1.0.6
#r "nuget: DNLiCore_DB, 1.0.6"
// Install DNLiCore_DB as a Cake Addin #addin nuget:?package=DNLiCore_DB&version=1.0.6 // Install DNLiCore_DB as a Cake Tool #tool nuget:?package=DNLiCore_DB&version=1.0.6
---介绍---
DNLiCore_DB 是属于DNLiCore框架下的一个数据库工具类,目标支持数据库类型包括 MySql,SqlServer,SqlLite
其中包括3种执行框架 Ado.net:SqlHelper,轻量级ORM:Petapoco,标准EF框架:EF Core
使用方法:1.安装 DNLiCore_DB
2.在appsettings.json配置对应的数据库配置,例如
"ConnectionStrings": {
"SqlServerConnection": "Server=******;Database=****;User ID=****;Password=*****;",
"MySqlConnection": "Database='*****';Data Source=****;User ID=****;Password=******.;CharSet=utf8;SslMode=None",
"SqlLiteConnection": "Data Source=ItcastCater.db"
}
3.在Startup.cs进行注入,例如使用mysql数据库
①使用ado.net 注入方式
services.AddSingleton(typeof(DNLiCore_DB.IMySqlHelper), new DNLiCore_DB.MySqlHelper(Configuration.GetConnectionString("MySqlConnection")));
②使用petapoco 注入方式,
services.AddSingleton(typeof(DNLiCore_DB.IPetaPocoHelper), new DNLiCore_DB.PetaPocoHelper(Configuration.GetConnectionString("MySqlConnection"), 0));
③使用ef注入方式
创建相应的DBContext和实体
1.1 通过程序包管理控制台生成DBContext和实体输入,按需引用DNLiCore_DB
Scaffold-DbContext -Force "Server=*****;User Id=****;Password=******;Database=drewtest" -Provider "Pomelo.EntityFrameworkCore.MySql"
注意:1.表必须要有主键
2.如果有需要只生成单表的加个 -Table 表名
3.会存在datetime数据类型实体生成错误的情况,需要手动修改
1.2 进行ef注入
services.AddSingleton(typeof(DNLiCore_DB.IRepository), new DNLiCore_DB.Repository(new DNLiCore_Model.drewtestContext()));
4.在控制器构造函数注入使用,此方法不唯一,例如
static DNLiCore_DB.IPetaPocoHelper mypetaPocoHelper;
public HomeController(DNLiCore_DB.IPetaPocoHelper petaPocoHelper)
{
mypetaPocoHelper = petaPocoHelper;
}
在其他方法中调用
public IActionResult Index()
{
var mylss = mypetaPocoHelper.Fetch(" select * from userInfo ");
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
- Microsoft.EntityFrameworkCore.Sqlite.Core (>= 2.1.4)
- Microsoft.EntityFrameworkCore.SqlServer (>= 2.1.4)
- PetaPoco.NetCore (>= 1.0.1)
- Pomelo.EntityFrameworkCore.MySql (>= 2.1.4)
- Z.EntityFramework.Extensions.EFCore (>= 2.1.41)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Summary of changes made in this release of the package.