Lotech.Data 2.0.16

dotnet add package Lotech.Data --version 2.0.16
NuGet\Install-Package Lotech.Data -Version 2.0.16
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="Lotech.Data" Version="2.0.16" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Lotech.Data --version 2.0.16
#r "nuget: Lotech.Data, 2.0.16"
#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.
// Install Lotech.Data as a Cake Addin
#addin nuget:?package=Lotech.Data&version=2.0.16

// Install Lotech.Data as a Cake Tool
#tool nuget:?package=Lotech.Data&version=2.0.16

Lotech.Data.Core

an ORM like "EnterpriseLib Data Block" for dotnet

使用

引用 Lotech.Data.dll

  • 前往 nuget.org 手工下载
  • 或 通过 Visual Studio 包管理器控制台安装
  Install-Package Lotech.Data.Core

配置 database.xml

配置包含驱动、连接串及默认设置内容,提供给 DatabaseFactory.Create()DatabaseFactory.Create(string connectionName) 使用

<database>
    <dbProviderFactories>
        
        <add name="System.Data.SqlClient" type="System.Data.SqlClient.SqlClientFactory, System.Data.SqlClient"/>        
    </dbProviderFactories>

    <connectionStrings>
        <add name="connection" providerName="System.Data.SqlClient"
             connectionString="Data Source=.; User Id=sa; Password=123456; Initial Catalog = example" />
    </connectionStrings>

    
    <databaseSettings defaultDatabase="connection" />
</database>

Api使用

实例化 IDatabase

  • 通过 DatabaseFactory 创建实例
  var db = new DatabaseFactory.Create();  // 使用默认连接创建
  var db = new DatabaseFactory.Create("connection");  // 使用指定的连接名创建
  • 直接创建对应实例
  var db = new SqlServerDatabase(System.Data.SqlClient.SqlClientFactory.Instance) {
    ConnectionString = "Data Source=.; User Id=sa; Password=123456; Initial Catalog = example; 
  };

配置SQL日志输出 Log

var db = DatabaseFactory.Create();
db.Log = message => Console.WriteLine(log);     // 将SQL执行日志输出到控制台

获取 DbCommand

  • 获取给定类型的 DbCommand 对象
    public DbCommand GetCommand(CommandType commandType, string commandText);

示例:

  var sqlCommand = db.GetCommand(CommandType.Text, "SELECT * FROM example");
  var procedureCommand = db.GetCommand(CommandType.Procedure, "MyProc");
  • 获取Text类型的 DbCommand 对象
    public DbCommand GetSqlStringCommand(string commandText);

示例:

  var sqlCommand = db.GetSqlStringCommand( "SELECT * FROM example");

执行存储过程 Procedure

using Lotech.Data;

class MyDAO {
  IDatabase db = DatabaseFactory.Create(); // use default database
  
  public MyEntity[] GetMyEntities(string userId, DateTime createDate) {
      // exec MyProc @userId, @date
      // db.ProcedureQuery is extension method, using Lotech.Data is required.
      return db.ProcedureQuery("MyProc", new {userId, date = createDate}).ExecuteEntities<MyEntity>();
  }
}
Product 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.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.16 146 5/23/2023
2.0.15 657 9/11/2020
2.0.14.2 643 12/5/2019
2.0.12 581 7/30/2019
2.0.10 669 3/26/2019
2.0.8 1,020 6/28/2018
2.0.6 1,000 6/8/2018
2.0.4 984 5/25/2018
2.0.2 850 5/23/2018
2.0.0 983 5/19/2018
1.4.2.2 1,323 8/11/2014