DASL.DapperWrapper
1.2.0
See the version list below for details.
dotnet add package DASL.DapperWrapper --version 1.2.0
NuGet\Install-Package DASL.DapperWrapper -Version 1.2.0
<PackageReference Include="DASL.DapperWrapper" Version="1.2.0" />
paket add DASL.DapperWrapper --version 1.2.0
#r "nuget: DASL.DapperWrapper, 1.2.0"
// Install DASL.DapperWrapper as a Cake Addin #addin nuget:?package=DASL.DapperWrapper&version=1.2.0 // Install DASL.DapperWrapper as a Cake Tool #tool nuget:?package=DASL.DapperWrapper&version=1.2.0
Usage:
Setup connection string in App.config and specifiy the name before making any calls to DapperWrapper.
DapperWrapper.ConnectionStringName = "my_db_connection";
Specify your db provider. Currently, MySql and MSSql are supported by this wrapper.
DapperWrapper.DbProvider = DapperWrapper.MYSQL_PROVIDER; // default
DapperWrapper.DbProvider = DapperWrapper.MSSQL_PROVIDER;
Note that some wrapper functions require the [Table(..)] attribute to be explicit.
Assuming this class...
[Table("users")]
public class User
{
public int Id { get; set; }
public string AccountCode { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Department { get; set; } = string.Empty;
public string AccountPassword { get; set; } = string.Empty;
}
var user1 = new User {....};
This is how you use the wrapper.
// inserts
int new_id = DapperWrapper.Insert(user1);
int new_id = await DapperWrapper.InsertAsync(user1);
// query
var user = DapperWrapper.Get<User>(23);
var user = await DapperWrapper.GetAsync<User>(23);
var user = DapperWrapper.GetByKeyField<User>("AccountEmail", "foo.bar@emailserver.foobar");
List<User> users = await DapperWrapper.GetAllByKeyField<User>("Department", "IT");
// updates
DapperWrapper.Update(user1);
await DapperWrapper.UpdateAsync(user1);
// delete
DapperWrapper.Delete(user1);
Custom SQL can be sent directly and a parameterized statement is constructed and sent to the database
var sql = "SELECT * FROM `user` WHERE Email=@email AND AccountPassword=@password";
var user = return await DapperWrapper.ExecuteSelectSingleAsync<User>(sql, new { email, password });
There are other available methods.
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. |
-
net8.0
- Dapper (>= 2.1.35)
- Dapper.Contrib (>= 2.0.78)
- MySql.Data (>= 8.3.0)
- MySqlConnector (>= 2.3.6)
- System.Data.SqlClient (>= 4.8.6)
- System.Drawing.Common (>= 8.0.4)
- Z.Dapper.Plus (>= 7.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Fixed name spaces and updated nuget packages