Luke.SqlProxy.Core
1.0.6
dotnet add package Luke.SqlProxy.Core --version 1.0.6
NuGet\Install-Package Luke.SqlProxy.Core -Version 1.0.6
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="Luke.SqlProxy.Core" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Luke.SqlProxy.Core" Version="1.0.6" />
<PackageReference Include="Luke.SqlProxy.Core" />
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 Luke.SqlProxy.Core --version 1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Luke.SqlProxy.Core, 1.0.6"
#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 Luke.SqlProxy.Core@1.0.6
#: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=Luke.SqlProxy.Core&version=1.0.6
#tool nuget:?package=Luke.SqlProxy.Core&version=1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Luke.SqlProxy
A Simple Proxy-Repository
How to use?
Program
static void Main(string[] args)
{
DbConnection connection = new MySqlConnection("Database=dev_test;Data Source=127.0.0.1;User Id=root;Password=123456;CharSet=utf8mb4;port=3306;Old Guids=true;");
ServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddTransient<IProxyDbContext>((sp) => new ProxyDbContext(connection));
serviceCollection.AddProxyRepositoryConfig(conf => { conf.AutoJoinTransaction = true; });
serviceCollection.AddTransientProxyRepository<IMyRepository>();
IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
IMyRepository proxy = serviceProvider.GetService<IMyRepository>();
DataTable dt = proxy.SelectData("Bob");
dt = proxy.SelectDataAsync("Bob").Result;
List<SysUser> users = proxy.SelectList("Bob");
users = proxy.SelectListAsync("Bob").Result;
SysUser user = proxy.SelectUser("Bob");
user = proxy.SelectUserAsync("Bob").Result;
List<int> ids = proxy.SelectId("Bob");
string name = proxy.SelectName(1);
proxy.DeleteUserAsync(2).Wait();
int count = proxy.InserUser(new SysUser { id = 2, name = "test" });
count = proxy.UpdateUser(new SysUser { id = 2, name = "test1" });
count = proxy.UpdateUserAsync(new SysUser { id = 2, name = "test2" }).Result;
int id = proxy.InserIdentityUser(new SysUser { name = "test" + DateTime.Now.ToString("yyMMddHHmmss") });
Console.Read();
}
IMyRepository
public interface IMyRepository
{
[Select("select * from sys_user where name = @name;")]
DataTable SelectData(string name);
[Select("select * from sys_user where name = @name;")]
Task<DataTable> SelectDataAsync(string name);
[Select("select * from sys_user where name = @name;")]
List<SysUser> SelectList(string name);
[Select("select * from sys_user where name = @name;")]
Task<List<SysUser>> SelectListAsync(string name);
[Select("select * from sys_user where name = @name;")]
SysUser SelectUser(string name);
[Select("select * from sys_user where name = @name;")]
Task<SysUser> SelectUserAsync(string name);
[Select("select * from sys_user where name = @name;")]
List<int> SelectId(string name);
[Select("select id from sys_user where name = @name;")]
Task<List<int>> SelectIdAsync(string name);
[Select("select name from sys_user where id = @id;")]
string SelectName(int id);
[Select("select name from sys_user where id = @id;")]
Task<string> SelectNameAsync(int id);
[Insert("insert into sys_user(id, name) values (@id, @name);")]
int InserUser(SysUser user);
[Update("update sys_user set name = @name where id = @id;")]
int UpdateUser(SysUser user);
[Update("update sys_user set name = @name where id = @id;")]
Task<int> UpdateUserAsync(SysUser user);
[Delete("delete from sys_user where id = @id;")]
void DeleteUser([DbParameterName("id")]int testid);
[Delete("delete from sys_user where id = @id;")]
Task DeleteUserAsync([DbParameterName("id")] int testid);
[Insert("insert into sys_user(name) values (@name);select @@identity;", selectIdentity: true)]
int InserIdentityUser(SysUser user);
}
ProxyDbContext
public class ProxyDbContext : IProxyDbContext, IDisposable
{
private readonly DbConnection _connection;
public ProxyDbContext(DbConnection connection)
{
_connection = connection;
}
public DbConnection GetCurrentDbConnection()
{
return _connection;
}
private DbTransaction? _transaction = null;
public DbTransaction? GetCurrentDbTransaction()
{
return _transaction;
}
public void BeginTransaction()
{
if (_transaction == null)
{
_transaction = _connection.BeginTransaction();
}
}
public void Dispose()
{
_connection.Dispose();
}
}
SysUser
public class SysUser
{
public int id { get; set; }
public string name { get; set; }
}
Return Type Maps
Attribute | Return Type | Example | Remark |
---|---|---|---|
SelectAttribute | List<[EntityClass]>,[EntityClass],Object,DataTable,String,[ValueType],List<string>,List<[ValueType]> | List<SysUser>,User,int,List<string> | |
DataTable | DataTable | ||
List<[EntityClass]> | List<SysUser> | ||
[EntityClass] | SysUser | ||
InsertAttribute | int,void,Object,[ValueType],String | int,void,object | |
UpdateAttribute | int,void | int,void | |
DeleteAttribute | int,void | int,void |
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. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.
-
.NETStandard 2.1
- Castle.Core (>= 5.0.0)
- Castle.Core.AsyncInterceptor (>= 2.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Luke.SqlProxy.Core:
Package | Downloads |
---|---|
Luke.SqlProxy.Dapper
A Simple Proxy-Repository |
GitHub repositories
This package is not used by any popular GitHub repositories.