{"id":20974937,"url":"https://github.com/usausa/smart-net-data-mapper","last_synced_at":"2025-05-14T13:32:17.315Z","repository":{"id":50546209,"uuid":"175163051","full_name":"usausa/Smart-Net-Data-Mapper","owner":"usausa","description":"Micro-orm mainly for environments that do not support code generation.","archived":false,"fork":false,"pushed_at":"2025-04-28T00:00:32.000Z","size":824,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T01:19:12.530Z","etag":null,"topics":["data-access","data-access-library","data-mapper","dataaccess","maui","micro-orm","orm","xamarin"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/usausa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-12T08:04:56.000Z","updated_at":"2025-04-28T00:00:36.000Z","dependencies_parsed_at":"2023-02-18T14:31:19.150Z","dependency_job_id":"2d72063d-0ede-4e76-99ab-91000714fde9","html_url":"https://github.com/usausa/Smart-Net-Data-Mapper","commit_stats":{"total_commits":255,"total_committers":1,"mean_commits":255.0,"dds":0.0,"last_synced_commit":"b64e769166b2e24caebad959a5b9af0e9e268a3a"},"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usausa%2FSmart-Net-Data-Mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usausa%2FSmart-Net-Data-Mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usausa%2FSmart-Net-Data-Mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usausa%2FSmart-Net-Data-Mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usausa","download_url":"https://codeload.github.com/usausa/Smart-Net-Data-Mapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254150600,"owners_count":22022992,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-access","data-access-library","data-mapper","dataaccess","maui","micro-orm","orm","xamarin"],"created_at":"2024-11-19T04:35:32.196Z","updated_at":"2025-05-14T13:32:12.293Z","avatar_url":"https://github.com/usausa.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Smart.Data.Mapper .NET - micro-orm library for .NET\r\n\r\n[![NuGet Badge](https://buildstats.info/nuget/Usa.Smart.Data.Mapper)](https://www.nuget.org/packages/Usa.Smart.Data.Mapper/)\r\n\r\n## What is this?\r\n\r\n* Smart.Data.Mapper .NET is simplified micro-orm library, degradation version of Dapper.\r\n* ***Main use is for environments that don't support code generation.***\r\n* Also support for environments that support code generation.\r\n\r\n### Usage example\r\n\r\n```csharp\r\n// Execute\r\nvar effect = con.Execute(\"INSERT INTO Data (Id, Name, Code) VALUES (@Id, @Name, @Code)\", new { Id = 1, Name = \"test\", Code = \"A\" });\r\n\r\n// Execute scalar\r\nvar count = con.ExecuteScalar\u003clong\u003e(\"SELECT COUNT(*) FROM Data WHERE Code = @Code\", new { Code = \"A\" });\r\n\r\n// Query list\r\nforeach (var entity in con.Query\u003cData\u003e(\"SELECT * FROM Data ORDER BY Id\"))\r\n{\r\n}\r\n\r\n// Query one\r\nvar entity = con.QueryFirstOrDefault\u003cData\u003e(\"SELECT COUNT(*) FROM Data WHERE Id = @Id\", new { Id = 1 });\r\n\r\n// Execute procedure\r\npublic sealed class TestProcParameter\r\n{\r\n    public int InParam { get; set; }\r\n\r\n    [Direction(ParameterDirection.Output)]\r\n    public long OutParam { get; set; }\r\n}\r\n\r\nvar parameter = new TestProcParameter { InParam = 1 };\r\ncon.Execute(\"TestProc\", parameter, commandType: CommandType.StoredProcedure);\r\nvar result = parameter.OutParam;\r\n```\r\n\r\n## NuGet\r\n\r\n| Package |\r\n|-|\r\n| [![NuGet Badge](https://buildstats.info/nuget/Usa.Smart.Data.Mapper)](https://www.nuget.org/packages/Usa.Smart.Data.Mapper/) |\r\n| [![NuGet Badge](https://buildstats.info/nuget/Usa.Smart.Data.Mapper.Builders)](https://www.nuget.org/packages/Usa.Smart.Data.Mapper.Builders/) |\r\n\r\n## Functions\r\n\r\n### Execute\r\n\r\n```csharp\r\nint Execute(this IDbConnection con, ISqlMapperConfig config, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)\r\n\r\nint Execute(this IDbConnection con, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)\r\n\r\nasync ValueTask\u003cint\u003e ExecuteAsync(this IDbConnection con, ISqlMapperConfig config, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken token = default)\r\n\r\nTask\u003cint\u003e ExecuteAsync(this IDbConnection con, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken token = default)\r\n```\r\n\r\n### ExecuteScalar\r\n\r\n```csharp\r\nT ExecuteScalar\u003cT\u003e(this IDbConnection con, ISqlMapperConfig config, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)\r\n\r\nT ExecuteScalar\u003cT\u003e(this IDbConnection con, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)\r\n\r\nasync ValueTask\u003cT\u003e ExecuteScalarAsync\u003cT\u003e(this IDbConnection con, ISqlMapperConfig config, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken token = default)\r\n\r\nTask\u003cT\u003e ExecuteScalarAsync\u003cT\u003e(this IDbConnection con, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken token = default)\r\n```\r\n\r\n### ExecuteReader\r\n\r\n```csharp\r\nIDataReader ExecuteReader(this IDbConnection con, ISqlMapperConfig config, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CommandBehavior commandBehavior = CommandBehavior.Default)\r\n\r\nIDataReader ExecuteReader(this IDbConnection con, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CommandBehavior commandBehavior = CommandBehavior.Default)\r\n\r\nasync ValueTask\u003cDbDataReader\u003e ExecuteReaderAsync(this IDbConnection con, ISqlMapperConfig config, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CommandBehavior commandBehavior = CommandBehavior.Default, CancellationToken token = default)\r\n\r\nTask\u003cDbDataReader\u003e ExecuteReaderAsync(this IDbConnection con, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CommandBehavior commandBehavior = CommandBehavior.Default, CancellationToken token = default)\r\n```\r\n\r\n### Query\r\n\r\n```csharp\r\nIEnumerable\u003cT\u003e Query\u003cT\u003e(this IDbConnection con, ISqlMapperConfig config, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)\r\n\r\nIEnumerable\u003cT\u003e Query\u003cT\u003e(this IDbConnection con, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)\r\n\r\nasync IAsyncEnumerable\u003cT\u003e QueryAsync\u003cT\u003e(this IDbConnection con, ISqlMapperConfig config, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancel = default)\r\n\r\nIAsyncEnumerable\u003cT\u003e QueryAsync\u003cT\u003e(this IDbConnection con, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancel = default)\r\n```\r\n\r\n### QueryList\r\n\r\n```csharp\r\nList\u003cT\u003e QueryList\u003cT\u003e(this IDbConnection con, ISqlMapperConfig config, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)\r\n\r\nList\u003cT\u003e QueryList\u003cT\u003e(this IDbConnection con, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)\r\n\r\nasync ValueTask\u003cList\u003cT\u003e\u003e QueryListAsync\u003cT\u003e(this IDbConnection con, ISqlMapperConfig config, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancel = default)\r\n\r\nTask\u003cList\u003cT\u003e\u003e QueryListAsync\u003cT\u003e(this IDbConnection con, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancel = default)\r\n```\r\n\r\n### QueryFirstOrDefault\r\n\r\n```csharp\r\nT QueryFirstOrDefault\u003cT\u003e(this IDbConnection con, ISqlMapperConfig config, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)\r\n\r\nT QueryFirstOrDefault\u003cT\u003e(this IDbConnection con, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)\r\n\r\nasync ValueTask\u003cT\u003e QueryFirstOrDefaultAsync\u003cT\u003e(this IDbConnection con, ISqlMapperConfig config, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken token = default)\r\n\r\nTask\u003cT\u003e QueryFirstOrDefaultAsync\u003cT\u003e(this IDbConnection con, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken token = default)\r\n```\r\n\r\n## Parameter/Result\r\n\r\n### Mapping option\r\n\r\n* Pascal and snake case support by default\r\n* NameAttribute support\r\n* IgnoreAttribute support\r\n\r\n### Parameter option\r\n\r\n* DirectionAttribute support\r\n* DbTypeAttribute support\r\n* SizeAttribute support\r\n* IgnoreAttribute support\r\n\r\n### DynamicParameter\r\n\r\n* Like Dapper\r\n\r\n### TypeHandler\r\n\r\n* Like Dapper\r\n\r\n## SqlMapperConfig\r\n\r\n### Propeties\r\n\r\n```csharp\r\n// Reflection api abstraction\r\nIDelegateFactory DelegateFactory { get; set; }\r\n\r\n// Type converter\r\nIObjectConverter Converter { get; set; }\r\n\r\n// Mapping property selector\r\nIPropertySelector PropertySelector { get; set; }\r\n```\r\n\r\n### Methods\r\n\r\n```csharp\r\n// Reset IParameterBuilderFactory's\r\nSqlMapperConfig ResetParameterBuilderFactories()\r\n\r\n// Supports DynamicParameter, IDictionary\u003cstring, object\u003e and object by default\r\nSqlMapperConfig ConfigureBuilderFactory(Action\u003cIList\u003cIParameterBuilderFactory\u003e\u003e action)\r\n\r\n// Reset IResultMapperFactory's\r\nSqlMapperConfig ResetResultMappers()\r\n\r\n// Supports object by default\r\nSqlMapperConfig ConfigureMapperFactory(Action\u003cIList\u003cIResultMapperFactory\u003e\u003e action)\r\n\r\n// Reset type map\r\nSqlMapperConfig ResetTypeMap()\r\n\r\n// Configure type map\r\nSqlMapperConfig ConfigureTypeMap(Action\u003cIDictionary\u003cType, DbType\u003e\u003e action)\r\n\r\n// Reset type handlers\r\nSqlMapperConfig ResetTypeHandlers()\r\n\r\n// Configure type handlers\r\nSqlMapperConfig ConfigureTypeHandlers(Action\u003cIDictionary\u003cType, ITypeHandler\u003e\u003e action)\r\n```\r\n\r\n## TODO\r\n\r\n* Multiple query support ?\r\n\r\n## Benchmark(for reference purpose only)\r\n\r\nBenchmark result on .NET Core 7 with Code generation mode.\r\n\r\n``` ini\r\n\r\nBenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22621.819)\r\nAMD Ryzen 9 5900X, 1 CPU, 24 logical and 12 physical cores\r\n.NET SDK=7.0.100\r\n  [Host]    : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2\r\n  MediumRun : .NET 7.0.0 (7.0.22.51805), X64 RyuJIT AVX2\r\n\r\nJob=MediumRun  IterationCount=15  LaunchCount=2  \r\nWarmupCount=10  \r\n\r\n```\r\n|                         Method |        Mean |     Error |    StdDev |      Median |         Min |         Max |         P90 |   Gen0 |   Gen1 | Allocated |\r\n|------------------------------- |------------:|----------:|----------:|------------:|------------:|------------:|------------:|-------:|-------:|----------:|\r\n|                  DapperExecute |   184.26 ns |  3.176 ns |  4.452 ns |   182.41 ns |   178.70 ns |   191.21 ns |   189.87 ns | 0.0271 |      - |     456 B |\r\n|                   SmartExecute |   104.52 ns |  0.839 ns |  1.203 ns |   104.79 ns |   102.71 ns |   106.78 ns |   106.13 ns | 0.0220 |      - |     368 B |\r\n|   DapperExecuteWithParameter10 |   446.17 ns |  2.022 ns |  2.963 ns |   446.59 ns |   439.95 ns |   451.81 ns |   449.78 ns | 0.0747 |      - |    1256 B |\r\n|    SmartExecuteWithParameter10 |   282.75 ns |  2.261 ns |  3.385 ns |   282.79 ns |   275.52 ns |   289.75 ns |   287.01 ns | 0.0747 |      - |    1256 B |\r\n| DapperExecuteWithOverParameter |   164.08 ns |  1.723 ns |  2.415 ns |   164.64 ns |   160.00 ns |   168.18 ns |   167.26 ns | 0.0281 |      - |     472 B |\r\n|  SmartExecuteWithOverParameter |   290.39 ns |  4.898 ns |  7.331 ns |   290.72 ns |   279.06 ns |   303.17 ns |   299.20 ns | 0.0747 |      - |    1256 B |\r\n|            DapperExecuteScalar |    58.85 ns |  0.201 ns |  0.301 ns |    58.86 ns |    58.34 ns |    59.45 ns |    59.22 ns | 0.0086 |      - |     144 B |\r\n|             SmartExecuteScalar |    52.41 ns |  1.257 ns |  1.762 ns |    52.36 ns |    50.27 ns |    55.10 ns |    54.50 ns | 0.0086 |      - |     144 B |\r\n| DapperExecuteScalarWithConvert |    88.37 ns |  1.996 ns |  2.926 ns |    86.94 ns |    84.98 ns |    94.95 ns |    92.06 ns | 0.0100 |      - |     168 B |\r\n|  SmartExecuteScalarWithConvert |    82.55 ns |  3.658 ns |  5.361 ns |    86.63 ns |    76.51 ns |    88.34 ns |    88.12 ns | 0.0100 |      - |     168 B |\r\n|                 DapperQuery100 | 2,917.63 ns | 15.512 ns | 22.737 ns | 2,917.30 ns | 2,880.38 ns | 2,965.22 ns | 2,949.00 ns | 0.3516 | 0.0039 |    5896 B |\r\n|                  SmartQuery100 | 1,601.73 ns |  9.355 ns | 14.002 ns | 1,599.81 ns | 1,580.57 ns | 1,637.07 ns | 1,621.92 ns | 0.2090 |      - |    3520 B |\r\n|          DapperQuery100Bufferd | 2,498.05 ns | 11.891 ns | 17.799 ns | 2,493.76 ns | 2,451.89 ns | 2,527.10 ns | 2,524.58 ns | 0.3477 | 0.0039 |    5856 B |\r\n|           SmartQuery100Bufferd | 1,718.58 ns | 15.172 ns | 22.709 ns | 1,715.81 ns | 1,675.41 ns | 1,765.25 ns | 1,750.48 ns | 0.3301 | 0.0039 |    5536 B |\r\n|               DapperQueryFirst |   254.31 ns |  1.509 ns |  2.259 ns |   254.65 ns |   249.74 ns |   257.06 ns |   256.85 ns | 0.0200 |      - |     336 B |\r\n|                SmartQueryFirst |   292.17 ns |  1.981 ns |  2.903 ns |   293.33 ns |   285.74 ns |   296.98 ns |   295.40 ns | 0.0146 |      - |     248 B |\r\n\r\nNot so late( ˙ω˙)?\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusausa%2Fsmart-net-data-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusausa%2Fsmart-net-data-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusausa%2Fsmart-net-data-mapper/lists"}