MapDataReader 1.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package MapDataReader --version 1.0.3
NuGet\Install-Package MapDataReader -Version 1.0.3
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="MapDataReader" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MapDataReader" Version="1.0.3" />
<PackageReference Include="MapDataReader" />
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 MapDataReader --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MapDataReader, 1.0.3"
#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 MapDataReader@1.0.3
#: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=MapDataReader&version=1.0.3
#tool nuget:?package=MapDataReader&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MapDataReader
Super fast mapping DataReader to a strongly typed object. High performance, lighweight (12Kb dll), uses AOT source generation and no reflection, mapping code is generated at compile time.
Benchmarks
20X faster than using reflection, even with caching. Benchmark for a tiny class with 5 string properties:
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|---|---|---|---|---|---|
| Reflection | 951.16 ns | 15.107 ns | 0.828 ns | 0.1459 | 920 B |
| MapDataReader | 44.15 ns | 2.840 ns | 0.156 ns | 0.0089 | 56 B |
Install via Nuget
Install-Package MapDataReader
Usage
using MapDataReader;
[GenerateDataReaderMapper] // <-- mark your class with this attribute
public class MyClass
{
public int ID { get; set; }
public string Name { get; set; }
public int Size { get; set; }
public bool Enabled { get; set; }
}
//ToMyClass() method code is generated at compile time
List<MyClass> result = dbconnection.ExecuteReader("SELECT * FROM MyTable").ToMyClass();
Some notes
- The
ToMyClass()method above - is an extension method generated at compile time. You can even "go to definition" in Visual Studio and examine its code. - The naming convention is
ToCLASSNAME()we can't use generics here, since<T>is not part of method signatures in C# (considered in later versions of C#). - Maps properies with public setters only.
- The reader is being closed after mapping, so don't reuse it.
- The example above uses
.ExecuteReadermethod from Dapper, but you can generate the reader in any way you want, e.g. the plainSqlCommand.ExecuteReaderwill also work. - Supports
enumproperties based onintand other implicit casting (sometimes a DataReader may decide to returnbytefor small integer database value, and it maps tointperfectly via some unboxing magic) - Properly maps
DBNulltonull. - Complex-type properties may not work.
- netstandard 2.0
- Contributions are very welcome.
| 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 | 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 | 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.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.3.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MapDataReader:
| Package | Downloads |
|---|---|
|
Thelegend107.SQL.Data.Lib
TheLegend107 SQL Database library. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.13 | 26,268 | 5/1/2024 |
| 1.0.12 | 297 | 4/26/2024 |
| 1.0.11 | 17,549 | 5/5/2023 |
| 1.0.10 | 13,153 | 1/20/2023 |
| 1.0.9 | 614 | 1/8/2023 |
| 1.0.8 | 3,953 | 11/28/2022 |
| 1.0.6 | 678 | 11/1/2022 |
| 1.0.5 | 610 | 10/28/2022 |
| 1.0.4 | 2,243 | 10/24/2022 |
| 1.0.3 | 870 | 10/13/2022 |
| 1.0.2 | 631 | 10/11/2022 |
| 1.0.1 | 580 | 10/10/2022 |
| 1.0.0 | 633 | 10/10/2022 |