godsharp - GodSharp.Data.Dapper 1.0.0

DbContext for Dapper.

PM> Install-Package GodSharp.Data.Dapper -Version 1.0.0 -Source https://www.myget.org/F/godsharp/api/v3/index.json

Copy to clipboard

> nuget.exe install GodSharp.Data.Dapper -Version 1.0.0 -Source https://www.myget.org/F/godsharp/api/v3/index.json

Copy to clipboard

> dotnet add package GodSharp.Data.Dapper --version 1.0.0 --source https://www.myget.org/F/godsharp/api/v3/index.json

Copy to clipboard
<PackageReference Include="GodSharp.Data.Dapper" Version="1.0.0" />
Copy to clipboard
source https://www.myget.org/F/godsharp/api/v3/index.json

nuget GodSharp.Data.Dapper  ~> 1.0.0
Copy to clipboard

> choco install GodSharp.Data.Dapper --version 1.0.0 --source https://www.myget.org/F/godsharp/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "godsharp" -SourceLocation "https://www.myget.org/F/godsharp/api/v2"
Install-Module -Name "GodSharp.Data.Dapper" -RequiredVersion "1.0.0" -Repository "godsharp" 
Copy to clipboard

GodSharp.Data.Dapper

DbContext for Dapper.

AppVeyor build status NuGet MyGet

Supported .NET Version

  • .NET Framework 3.5+
  • .NET Standard 1.3
  • .NET Standard 2.0

Getting Started

  1. Install Nuget Package.

See here.

  1. Inherited class DapperDbContext.

Use connectionString name in App.Config or Web.config as constructor parameters.

If your project type is .NET Core,you should add json setting for connectionStrings and DbConnectionFactories,format reference here.

public class IRepository:DbContext
{
    public IRepository():base("db")
    {
    }
}

Or override OnConfiguration method, invoke Use method.

public class IRepository : DbContext
{
    public IRepository()
    {
    }

    protected override void OnConfiguration(DbConnectionFactory factory)
    {
        base.OnConfiguration(factory);
        string providerName= "MySql.Data.MySqlClient";
        string connectionString= "Data Source=127.0.0.1;Initial Catalog=user;User Id=root;Password=root;Charset=utf8;";
        factory.Use(providerName, connectionString);
    }
}
  1. Define data objects.
public class TestRepository : IRepository
{
	public bool Connected()
	{
		try
		{
			object obj = ExecuteScalar("SELECT CONVERT(varchar(50), GETDATE(), 25);", null, null, CommandType.Text);

			if (obj == null)
			{
				return false;
			}

			string dt = obj.ToString();

			DateTime _dt;

			return DateTime.TryParse(dt, out _dt);
		}
		catch (Exception ex)
		{
			throw ex;
		}
	}
}

Execute Sql with transaction.

public class TestRepository : IRepository
{
	public bool ExecuteWithTran()
    {
        string sql = null;
        object param = null;

        // begin tran
        BeginTransaction();

        // execute sql
        Execute(sql, param);
            
        // commit tran
        Commit();

        // or
        // callback tran
        //Callback();
    }
}

License

Licensed under the MIT License.

Supported loop transaction.

  • .NETFramework 3.5
    • Dapper (>= 1.40.0 && <= 1.42.0)
  • .NETFramework 4.0
    • Dapper (>= 1.50.0 && <= 1.50.2)
  • .NETFramework 4.5
    • Dapper (>= 1.50.0 && <= 1.50.2)
  • .NETFramework 4.5.1
    • Dapper (>= 1.50.0)
  • .NETStandard 1.3
    • Dapper (>= 1.50.0)
    • GodSharp.Data.Common.DbProvider (>= 1.0.0-preview1)
    • NETStandard.Library (>= 1.6.1)
    • System.Data.Common (>= 4.3.0)
  • .NETStandard 2.0
    • Dapper (>= 1.50.4)
    • GodSharp.Data.Common.DbProvider (>= 1.0.0-preview1)
  • .NETFramework 3.5: 3.5.0.0
  • .NETFramework 4.0: 4.0.0.0
  • .NETFramework 4.5: 4.5.0.0
  • .NETFramework 4.5.1: 4.5.1.0
  • .NETStandard 1.3: 1.3.0.0
  • .NETStandard 2.0: 2.0.0.0

Owners

Seay

Authors

seayxu

Project URL

https://github.com/godsharp/GodSharp.Data.Dapper

License

MIT

Tags

Dapper,GodSharp.Data.Dapper,GodSharp

Info

3 total downloads
1 downloads for version 1.0.0
Download (39.12 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
1.0.0 39.12 KB Thu, 16 Aug 2018 04:54:28 GMT 1
1.0.0-preview6 54.67 KB Thu, 21 Sep 2017 14:33:32 GMT 0
1.0.0-preview5 54.65 KB Sun, 17 Sep 2017 05:23:04 GMT 0
1.0.0-preview4 53.22 KB Sat, 16 Sep 2017 12:14:13 GMT 2